Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
earthling
Frequent Visitor

Cumulative sum for non-continuous dates: filling in daily sums for unique records

Hi all I am having difficulty solving (what seems to be) a complex cumulative sum problem.

 

Each row below is a unique individual with their own term (Start date, End date), and daily wage earned for their respective term (Salary Amount D is not total $ earned for the term, but the $ earned per day of the term).

 

I need a continuous daily cumulative sum of Salary Amount D for each record, up to its end date, across all records for the period. However:

  • Start and End dates are not uniform across all records
  • Start dates are not continuous thus there is no continuous 'daily wage' for each record
  • Creating an overall cumulative sum is straight forward, but the sum for each row must stop at it's respective end date

earthling_0-1666372285084.png

The situation is modeled (somewhat) graphically below, with each colored line representing a unique row start and end dates, all occuring within the minimum Start, and max End

earthling_1-1666373847235.png

For context, My goal is to see on which specific date on the timeline a cumulative earnings target was met.

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@earthling,

 

Try this solution.

 

1. Create calculated table:

 

DailySalary = 
GENERATE ( Salary, CALENDAR ( Salary[Start Date], Salary[End Date] ) )

 

2. Create date table (if you don't already have one):

 

DimDate = CALENDARAUTO()

 

3. Create relationship:

 

DataInsights_0-1666444687828.png

 

4. Create measures:

 

Salary = SUM ( DailySalary[Salary Amount D] )
Cumulative Salary = CALCULATE ( [Salary], DimDate[Date] <= MAX ( DimDate[Date] ) )

 

5. Create visual using DimDate[Date]:

 

DataInsights_1-1666444816640.png

 

Sample data:

 

DataInsights_2-1666444835075.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
DataInsights
Super User
Super User

@earthling,

 

Try this solution.

 

1. Create calculated table:

 

DailySalary = 
GENERATE ( Salary, CALENDAR ( Salary[Start Date], Salary[End Date] ) )

 

2. Create date table (if you don't already have one):

 

DimDate = CALENDARAUTO()

 

3. Create relationship:

 

DataInsights_0-1666444687828.png

 

4. Create measures:

 

Salary = SUM ( DailySalary[Salary Amount D] )
Cumulative Salary = CALCULATE ( [Salary], DimDate[Date] <= MAX ( DimDate[Date] ) )

 

5. Create visual using DimDate[Date]:

 

DataInsights_1-1666444816640.png

 

Sample data:

 

DataInsights_2-1666444835075.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@DataInsights 

This is great so far. However I am running into an issue of Cumulative Sum summing Emp ID wages outside of their term dates:

earthling_0-1666459589781.png

For example EMP ID 1, 2, 3 did not start on 10/02/2021. What could be causing this? Here are my meaures for reference

 

DailySalary = GENERATE( Data, CALENDAR(MIN(Data[Start Date]), MAX(Data[End Date]) ))
DateDim = CALENDARAUTO()
Salary = SUM( DailySalary[Salary Amount D])
Cumulative Salary = CALCULATE( [Salary], 'DateDim'[Date] <= MAX('DateDim'[Date]))
 
Data in visual:
earthling_1-1666460088436.png

 

@earthling,

 

Try removing MIN and MAX from the calculated table DailySalary. The GENERATE function is an iterator, so there is a row context.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Perfect. I had recieved an error when removing min and max, as 2 End Date rows were null. The problem was resolved after filtering out the nulls in power query.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.