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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
audreyf
New Member

Rolling SUM with Expiration Date

I am trying to get a rolling measure and I am struggling to get the desired results. Below is an example of the data I am trying to summarize. 'Start' has a N:1 relationship with the Date table. My goal is to sum "Column" as long as the month is within the periods. 

StartEndColumn
3/9/20206/17/2020100
3/16/20206/30/202040
3/19/20204/3/202060
4/3/20204/10/202020
4/6/20204/17/202080
4/6/20204/17/202080
4/6/20205/22/202025
4/16/20204/21/20200
4/21/20205/21/202060
5/11/20205/15/202015
6/4/20206/8/20205
7/1/20208/31/202080


An example of the output would be grouped on the month in the date table:

March-20200
April-20465
May-20240
June-20145
July-2080


I can get the column to sum in a cumulative fashion, with the below DAX, but I cannot seem to use the inverse with "End" to drop the values expired, because for example, March has some values that should carry until June, while others should be dropped in April, so it seems to drop one or the other. 

 

Measure = 
CALCULATE(
	SUM('table'[Column]),
	FILTER(
		ALLSELECTED(Dates[Date]),
		ISONORAFTER(Dates[Date], MAX('table'[Start]),DESC)
))

 

 I could use some direction on a better approach. 

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Please try this expression instead.  This got your desired result in a table visual with the YearMonth column from the Date table.

 

Total Between =
VAR mindate =
MIN ( 'Date'[Date] )
VAR maxdate =
MAX ( 'Date'[Date] )
RETURN
CALCULATE (
SUM ( 'Table'[Column] ),
ALL ( 'Table' ),
'Table'[Start] <= maxdate,
'Table'[End] >= mindate
)

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Employee
Employee

Please try this expression instead.  This got your desired result in a table visual with the YearMonth column from the Date table.

 

Total Between =
VAR mindate =
MIN ( 'Date'[Date] )
VAR maxdate =
MAX ( 'Date'[Date] )
RETURN
CALCULATE (
SUM ( 'Table'[Column] ),
ALL ( 'Table' ),
'Table'[Start] <= maxdate,
'Table'[End] >= mindate
)

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat Thank you! The exact outcome I needed. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors