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
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
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.