Forum Discussion

MSaunders206's avatar
MSaunders206
Frequent Visitor
8 years ago
Solved

Cumulative total with dates that do not have values

I'm looking to create a measure that counts cumulative totals and just cannot seem to find the right solution.  I have a table called "tblWorkStatus" that looks like this:

Work_statusdate
12018-11-01
22018-06-01
32018-12-01
42018-06-01
52018-05-01
32018-10-01
32018-06-01
32018-03-01
32018-06-01
32019-11-01
32018-02-01
32018-03-01
32018-05-01
32018-12-01

 

I have another table called tblDate that has the first of the month dates for all dates between 2018-01-01 and 2019-12-01.

 

DateMonth
2018-01-011
2018-02-012
2018-03-013
2018-04-014
2018-05-015
2018-06-016
2018-07-017
2018-08-018
2018-09-019
2018-10-0110
2018-11-0111
2018-12-0112
2019-02-012
2019-03-013
2019-04-014
2019-05-015
2019-06-016
2019-07-017
2019-08-018
2019-09-019
2019-10-0110
2019-11-0111
2019-12-0112

 

I'd like to have a running cumulative total of all work status "3".  I've created a measure called "Total_to_Date", but what I really desire is "what_I_want".

 

Total_to_date:=calculate(counta(tblWorkStatus[Work_status]),tblWorkStatus[Work_status]=3,filter(all(tblDate[date]),tblDate[date]<=max(tblWorkStatus[date])))

 

DatesCount of Work StatusTotal_to_Datewhat_I_want
2018-01-01  0
2018-02-01111
2018-03-01233
2018-04-01  3
2018-05-01144
2018-06-01266
2018-07-01  6
2018-08-01  6
2018-09-01  6
2018-10-01177
2018-11-01  7
2018-12-01299
2019-02-01  9
2019-03-01  9
2019-04-01  9
2019-05-01  9
2019-06-01  9
2019-07-01  9
2019-08-01  9
2019-09-01  9
2019-10-01  9
2019-11-0111010
2019-12-01  10

 

I can't seem to figure out how to get my calculated measure to fill in total values if there is no corresponding work status for a given month.  I've pored over several posts on the forum to no avail.  Any help?

12 Replies

  • Hi,

     

    You may download my PBI file from here.

     

    Hope this helps.

     

    • MSaunders206's avatar
      MSaunders206
      Frequent Visitor

      This certainly has the behavior that I'm looking for.  I downloaded the PBIX file and am viewing with the web interface, but cannot seem to find the calculation for the "YTD work status count" field.  What is the formula for the calculation?

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        Hi,

         

        In PowerBI desktop, click on the measure on the right hand side pane and you will see the measure in the formula bar.

  • Your close need to specifybtbe date table name as a term in the calculate to force the filter context to between the two tables.

    Total_to_date:=calculate(counta(tblWorkStatus[Work_status]),tblWorkStatus[Work_status]=3,tbleDate,filter(all(tblDate[date]),tblDate[date]<=max(tblWorkStatus[date])))
    • MSaunders206's avatar
      MSaunders206
      Frequent Visitor

      Thanks for the input Seward.  When I tried your formula, it gave me the same values as "Count of Work Status".