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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors