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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Cummulative sum based on slicer selection

Hi Team,

 

Currently We've developed a visual showing that last 6 months of salesamount based on slicer(Month-Year) selection.

Problem Statement : Need to calculate dynamic cummulative sum of the last 6 months based on the slicer selection

 

Attached is the PBI Ref link : https://1drv.ms/u/s!Au-aOkl1BoHuhxIPCmu25tKY_HLm?e=dFRnwZ


For Ex:1 if we select dec-2017 then will showcase last 6 months(Dec-2017,nov-2017,oct-2017,sep-2017,aug-2017,july-2017)

   Ex2:if we select Aug-2018 then will showcase last 6 months(Aug-2018,July-2018,June-2018,May-2018,April-2019,Mar-2018)

 

Current OutPut

Current Image.png

Expected OutPut:

Cummulative Sum.png

 

Power BI Reference Link:

https://1drv.ms/u/s!Au-aOkl1BoHuhxIPCmu25tKY_HLm?e=dFRnwZ

 

Thanks In Advance

 

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Here is one way

Vera_33_0-1637629939386.png

Sales (last n months) 1 = 
VAR MaxFactDate =
   CALCULATE ( MAX ( Sales[Date] ), ALL ( 'Date' ) ) -- ignore the selected date filter, and find the max of date in Sales table 
VAR FDate =
    ENDOFMONTH ( 'Date'[Date] ) -- get the last day of the month selected in the date filter
VAR Edate =
    EDATE ( FDate, -6 ) -- get the last day of -N months
RETURN
    IF(MaxFactDate<=FDate,
  SUMX(FILTER(ALL('Sales'),'Sales'[Date]<=MaxFactDate&&'Sales'[Date]>=Edate),Sales[Sales]))

 

View solution in original post

1 REPLY 1
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Here is one way

Vera_33_0-1637629939386.png

Sales (last n months) 1 = 
VAR MaxFactDate =
   CALCULATE ( MAX ( Sales[Date] ), ALL ( 'Date' ) ) -- ignore the selected date filter, and find the max of date in Sales table 
VAR FDate =
    ENDOFMONTH ( 'Date'[Date] ) -- get the last day of the month selected in the date filter
VAR Edate =
    EDATE ( FDate, -6 ) -- get the last day of -N months
RETURN
    IF(MaxFactDate<=FDate,
  SUMX(FILTER(ALL('Sales'),'Sales'[Date]<=MaxFactDate&&'Sales'[Date]>=Edate),Sales[Sales]))

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.