Forum Discussion

my76's avatar
my76
Frequent Visitor
6 years ago

Cumulative DISTINCTCOUNT with time intelligence

I am having trouble with DAX and need some help! Here is what I am trying to do:

 

I want to report on DISTINCTCOUNT of TenantID cumulatively by Week, Month and Quarter. Below is what I have attempted for Month but it is only returning the distinct count per day and not cumulatively for the Month. I am creating it as a Measure in the table 'MAC over QuAC' which has a relationship with the 'pageviews' table using timestamp/date columns.

Cumulative Tenant Count by Month =
CALCULATE(
CALCULATE(DISTINCTCOUNT(pageviews[TenantID]),
FILTER(pageviews, pageviews[timestampformatted] <= pageviews[timestampformatted]),
DATESMTD('MAC over QuAC'[Date])))


Once I figure this out I also need to work out how to report on a rolling 30d and 90d basis where the daily value is recalculated each day.

Thanks in advance!
Matt

5 Replies

  • v-juanli-msft's avatar
    v-juanli-msft
    Icon for Community Support rankCommunity Support

    Hi my76 

    You could get the cumulatively DISTINCTCOUNT of TenantID by Week, Month and Quarter..

    First create a date table with date, year, Week, Month and Quarter.

    Then create a relationship between this date table and your main table.

    then create a measure to get DISTINCTCOUNT of TenantID,

    Measure = DISTINCTCOUNT(Sheet2[id])
    
    

    after add year, Quarter, Month, Week, in the row field of the matrix, the measure can change based on expanding to each level.

    you can create a measure to get the cumulatively DISTINCTCOUNT of TenantID by Week, Month and Quarter.

    Measure 2 = CALCULATE(DISTINCTCOUNT(Sheet2[id]),FILTER(ALLSELECTED(Sheet2),Sheet2[timestamp]<=MAX(Sheet2[timestamp])))

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    • my76's avatar
      my76
      Frequent Visitor

      v-juanli-msft  really helpful example but we are not quite there yet...

       

      Whilst measure 2 gives a DISTINCTCOUNT, it does so cumulatively over the whole reporting period. i.e. August is a DISTINCOUNT from the earliest date (March) to the August dated rows. The resulting lin chart shows an increasing trend over the full period; when each Monthly period actually has fluctuating DISTINTCOUNTS e.g. August has 3 DISTINCTOUNT values, but Measure 2 reports it as 4. I can get the monthly values using Measure 1 (DISTINTCOUNT of ID).

       

      I need the values to use in a formula = ID count by Month / ID count by Quarter

       

      Maybe creating a separate table with the Distintcounts over Day/Week/Month/Quarter/Year periods would be the answer?

       

      Once we have the above working I need it to show the DISTINTCOUNT for Weekday to Date, Week to Date, Month to Date, Quarter to Date in the context of the full reporting period. 

       

      Also, how can I calculate the DISTINCTCOUNT for the last 90 days to get a rolling 90 day value each day?

      • my76's avatar
        my76
        Frequent Visitor

        **Bump** 

         

        Any more ideas? 

         

        Thanks

        Matt