Create Data that does not exist
Hey all, I am working with some usage data for some of our products. What I am trying to do is be able to flag if there is zero usage on a account. our daily files only include usage but not if there is no usage. I have contract End dates that I can use to say something like if contract is active with no usage pull that data in, but what I am having issues on is being able to find those zero usage accounts because there are no data points. Any thoughts?
Thanks!
Comments
-
Hi @kacy
If you have a contract start date and end date and you're looking at the dates in between you'll need to join your usage table to a date dimension table. Domo has a dataset of Dates (Cloud App > Domo Dimensions > calendar.csv). You can select the date from the date dimension table and left join it to your usage table. This will give you all the dates between two dates along with the count or null if there are no records (you can use coalesce to force these to 0).
Rough example:
SELECT d.`Date`, COALESCE(u.`Count`) as "Count" from `Dates` d left join `Usage` u on u.`Date` = d.`Date`
You could also do this within MagicETL using the appropriate tiles.
Since you have contract start and end dates you may want to restrict the entries further so that you don't have dates for a contract outside the contract dates.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**3 -
@kacy in order to analyze usage, particularly in the context of 'no usage', you have to have two pieces of data
1) a list of all the product contracts (it sounds like you have a start date and end date) -- one row per contract
2) a list of daily usage (it sounds like you get that already) -- one row per day the contract is used.
Once you have those two things, you can modify your list of contracts as @GrantSmith described except, when you JOIN to the date dimension you'll JOIN on a BETWEEN clause
CREATE TABLE contract_daily
SELECT
c.*
d.date
FROM
contract c
JOIN
date d
ON d.date between c.contractStartDate and c.contractEndDate
This will blow out your contract table into one row for each day the contract was active.
You can then LEFT JOIN contract_daily to your contract_usage
SELECT
cd.*
CASE when cu.contractID is null then 'Not Used' else 'Used' END
FROM
contract_daily cd
LEFT JOIN
contract_usage cu
ON
cd.contractID = cu.contractID
and cd.date = cu.contractUsageDate
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"2 -
Thanks both! I will give this a try
Thanks!
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive