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

  • GrantSmith
    GrantSmith Indiana 🔴

    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.

  • jaeW_at_Onyx
    jaeW_at_Onyx Budapest / Portland, OR 🟤

    @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

     

  • kacy
    kacy ⚪️

    Thanks both! I will give this a try

    Thanks!