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?



  • GrantSmith

    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!**
  • jaeW_at_Onyx

    @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




    contract c


    date d

    ON 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




    CASE when cu.contractID is null then 'Not Used' else 'Used' END


    contract_daily cd


    contract_usage cu


    cd.contractID = cu.contractID

    and = 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"
  • kacy
    kacy Member

    Thanks both! I will give this a try