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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Ben1981
Helper III
Helper III

Aggregate Sum with specific dates

Having trouble with what should be a simply DAX measure but I can't see what I'm doing wrong, I'm trying to achieve the below...

I have a static table with a few columns in such as Month and Customer Count and Data Type.


I want to do a sum of the customer Count when the data type is "current" but a sort of rolling 4 month aggregate. So the measure will do a SUM of customer count for each month back dated 4 months from the current month but only when the data type is current.

So an example below, for the month of 01/12/2024, I'm essentially doing a SUM of the count from 01/09/2024 to 01/09/2024 and then the next month I'll do a SUM of 01/01/2025 from 01/10/2024.

Ben1981_0-1728290617692.png

 



1 ACCEPTED SOLUTION

Hi @Ben1981@Muhammad_Ahmed 

This solution has the right idea, but you are missing an ALL from th filter conditions.

See below my adjusted measure:

NewMeasure = 

VAR currMonth = SELECTEDVALUE('Table'[Month])
VAR rolling4months = DATESINPERIOD('Table'[Month],currMonth,-4,MONTH)


RETURN
CALCULATE(SUM('Table'[Cust Count]),ALL(),'Table'[Data Type]="Current",'Table'[Month] IN rolling4months)


and a table comparing the results:

 




dk_dk_1-1728293179128.png

 

 

"Measure" is the reference column from the example table provided. NewMeasure is my measure.





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

Proud to be a Super User!





View solution in original post

3 REPLIES 3

Hi, 
Thank you for sharing your problem.
Can you try it out.
Rolling 4-Month Cust Count =
CALCULATE(
SUM('Table'[Cust Count]),
'Table'[Data Type] = "Current",
DATESINPERIOD(
'Table'[Month],
MAX('Table'[Month]),
-4,
MONTH
)
)

Hi @Ben1981@Muhammad_Ahmed 

This solution has the right idea, but you are missing an ALL from th filter conditions.

See below my adjusted measure:

NewMeasure = 

VAR currMonth = SELECTEDVALUE('Table'[Month])
VAR rolling4months = DATESINPERIOD('Table'[Month],currMonth,-4,MONTH)


RETURN
CALCULATE(SUM('Table'[Cust Count]),ALL(),'Table'[Data Type]="Current",'Table'[Month] IN rolling4months)


and a table comparing the results:

 




dk_dk_1-1728293179128.png

 

 

"Measure" is the reference column from the example table provided. NewMeasure is my measure.





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

Proud to be a Super User!





rajasaadk_98
Helper I
Helper I

To create a rolling 4-month aggregate of the customer count in Power BI (DAX), where you only sum the Customer Count for months classified as "Current", you can use the CALCULATE function along with FILTER to control the time range and data type.

Here's the DAX measure that will accomplish this:
Rolling4MonthCustomerCount =
CALCULATE(
SUM('YourTable'[Cust Count]),
FILTER(
'YourTable',
'YourTable'[Month] <= EARLIER('YourTable'[Month]) &&
'YourTable'[Month] >= EDATE(EARLIER('YourTable'[Month]), -3) && -- Going back 3 months (4 months total)
'YourTable'[Data Type] = "Current" -- Only include "Current" data type
)
)


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.