Forum Discussion

Maria7's avatar
Maria7
Frequent Visitor
3 years ago

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 

 

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