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
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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.