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 August 31st. Request your voucher.

Reply
NidhiBhusari
Helper IV
Helper IV

Calculate cumulative values for selected months

Hi All,

Here is the scenario where i want to calculate total value for month selected. ALso the values of previous 2/3 months should get calculated. Ex- if i select April from slicer then in the matrix it should cummulative sum of february, March and April.

Can anyone please help me with the DAX?
NidhiBhusari_0-1631530930097.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @NidhiBhusari ,

 

Please use the following formula to create a measure and then apply it to visual-level filter, set as "is 1".

Flag =
VAR _sele =
    DATE ( SELECTEDVALUE ( 'ForSlicer'[Date].[Year] ), SELECTEDVALUE ( 'ForSlicer'[Date].[MonthNo] ), 1 )
VAR _date =
    DATE ( MAX ( 'Table'[Date].[Year] ), MAX ( 'Table'[Date].[MonthNo] ), 1 )
RETURN
    IF ( DATEDIFF ( _date, _sele, MONTH ) IN { 0, 1, 2 }, 1 )

But based on my test, it seems that the selection in slicer could not related to Columns field in Matrix, so I'd suggest you put Company to Columns field and Date(Year and Month) to Rows field in matrix:'

Eyelyn9_0-1631778332979.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @NidhiBhusari ,

 

Please use the following formula to create a measure and then apply it to visual-level filter, set as "is 1".

Flag =
VAR _sele =
    DATE ( SELECTEDVALUE ( 'ForSlicer'[Date].[Year] ), SELECTEDVALUE ( 'ForSlicer'[Date].[MonthNo] ), 1 )
VAR _date =
    DATE ( MAX ( 'Table'[Date].[Year] ), MAX ( 'Table'[Date].[MonthNo] ), 1 )
RETURN
    IF ( DATEDIFF ( _date, _sele, MONTH ) IN { 0, 1, 2 }, 1 )

But based on my test, it seems that the selection in slicer could not related to Columns field in Matrix, so I'd suggest you put Company to Columns field and Date(Year and Month) to Rows field in matrix:'

Eyelyn9_0-1631778332979.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@NidhiBhusari , A measure like example with help from date table

 

Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,MONTH))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak , i tried implementing this but is not giving expected output. Can you please suggest any other way to achieve this?

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.