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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

DAX formula to get cumulative sales with SELECTEDVALUE

Hello,

 

I want to create a barchart that will show the cululative total sales over a period of selected months by the user. In the X-axis will be the month(s) and in the Y-axis the sales measure.

My struggling point is that in Y-axis I use so far a measure that includes a SELECTEDVALUE function, since I have a filter with 3 different Sales metrics:

Metric = 
VAR MySelection =
SELECTEDVALUE ( 'Measures'[Selection], "Sales" )
RETURN
SWITCH (
    TRUE (),
    MySelection = "Value", [Sales Value],
    MySelection = "Items", [Sales Items],
    MySelection = "Units", [Sales Units],
    blank()
)

 

Any idea how can I convert my DAX code above, in order to get cumulative Sales?

 

Thanks! 

 

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Firstly, rather than your current solution you should look into using a fields parameter. they are specifically designed to allow the user to choose which metric to show.

To solve the problem of being able to toggle between accumulated or not you could use a calculation group with 2 items. The first item would just call SELECTEDMEASURE(), so returning the non-cumulative values. The second calculation item could be

Cumulative in period =
VAR StartDate =
    CALCULATE ( MIN ( 'Date'[Date] ), ALLSELECTED ( 'Date' ) )
VAR EndDate =
    MAX ( 'Date'[Date] )
VAR Result =
    CALCULATE (
        SELECTEDMEASURE (),
        DATESBETWEEN ( 'Date'[Date], StartDate, EndDate )
    )
RETURN
    Result

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

Firstly, rather than your current solution you should look into using a fields parameter. they are specifically designed to allow the user to choose which metric to show.

To solve the problem of being able to toggle between accumulated or not you could use a calculation group with 2 items. The first item would just call SELECTEDMEASURE(), so returning the non-cumulative values. The second calculation item could be

Cumulative in period =
VAR StartDate =
    CALCULATE ( MIN ( 'Date'[Date] ), ALLSELECTED ( 'Date' ) )
VAR EndDate =
    MAX ( 'Date'[Date] )
VAR Result =
    CALCULATE (
        SELECTEDMEASURE (),
        DATESBETWEEN ( 'Date'[Date], StartDate, EndDate )
    )
RETURN
    Result

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.