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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Maria7
Frequent Visitor

Cumulative function based on a date range filter

Hi everyone,

 

I'm pretty new to using DAX function in Power BI and I'm having a hard time trying to create a cumulative function based on certain requirements. Please, someone help or maybe give some ideas on how I could modify the formula so that it does what I want. Any help would be appreciated.

 

I have one date range filter in the report page 

Maria7_0-1688643760722.png

 

and based on this I want to calculate the cumulative function in the following way:

- for the first month in the range to have the result obtained from 3 measures, like this: measure1-measure2+measure3 

- and for the next months, until the last date in the date range filter, to take the result from the previous month + measure1- measure2. 

The date filter is taken form a DateTable which is linked with the tables where the measures are.

The formula that I have right now is this :

 

CumulativeResult =

VAR StartDate = MIN('datatable'[Date])

VAR EndDate = MAX('datatable'[Date])

VAR SelectedRange = FILTER('datatable', 'datatable'[Date] >= StartDate && 'datatable'[Date] <= EndDate)

RETURN

    SUMX(

        SelectedRange,

        IF(

            'datatable'[Date] = StartDate,

            [measure1] - [measure2] + [measure3],

            CALCULATE(

                [measure1] - [measure2],

                FILTER(

                    ALL('datatable'),

                    'datatable'[Date] = EARLIER('datatable'[Date])

                )

            )

        )

)
 
Thanks!
1 REPLY 1
lbendlin
Super User
Super User

Most of the manual work you did can be gotten for free through the filter context.  Using ALLSELECTED(), for example.

 

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.