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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Antmkjr
Post Patron
Post Patron

Cumulative over Cumulative issue

https://drive.google.com/file/d/1pWvFXrZcE9s8QAq9dBjkaBSEUlJMJCRD/view?usp=sharing

14.PNG

 

I am trying to get the cumulative of EW , and it is not working.

 

I am using the below formula:

 

Cumulative EW =
CALCULATE([EW], FILTER (
ALLSELECTED ( 'Date' ),
'Date'[Date] <= MAX ( 'Date'[Date] ) ))
 
I understand there is some context that i have to break, ths can be done by creating a calculated table and then a measure as below:
BreakContextTransitionTable = 
VAR __YMTable = SUMMARIZE(ALL('Date'), 'Date'[MonthnYear])
VAR __YMTableEW = ADDCOLUMNS(__YMTable, "@EW", [EW])
RETURN
__YMTableEW

 

EW = 
VAR __filter = FILTER(BreakContextTransitionTable, BreakContextTransitionTable[MonthnYear] <= MAX('Date'[MonthnYear]))
RETURN
SUMX(__filter, BreakContextTransitionTable[@EW])

 

But can anyone let me know, how can this be done in a single measure , without creating a new calculated table.

11 REPLIES 11
stevedep
Memorable Member
Memorable Member

@Antmkjr , Can you add some sample data & expected outcome. I am unable to download files. We can fix this for you. 

https://drive.google.com/file/d/1pWvFXrZcE9s8QAq9dBjkaBSEUlJMJCRD/view?usp=sharing

 

Could you please check if you are able to download this?

 

Expected Outcome:

 

AnuTomy_0-1614061111200.png

 

mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression.  It is a little slow but that may be because of your existing measures that it references.

 

NewMeasure =
VAR vMaxDate =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUMX (
            VALUES ( 'Date'[MonthInCalendar] ),
            [EW]
        ),
        FILTER (
            ALL ( 'Date'[Date] ),
            'Date'[Date] <= vMaxDate
        )
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks @mahoneypat , but this measure seems to be extremely slow even with small data.

And my actual model is very huge 😞

Any ways to improve performance?

Here is a new measure that avoid referencing your other measures.  I ran out of time before work, but it is very close and much faster.  Hopefully, you can tweak it from here.  If not, I can finish it this evening.

 

NewMeasure3 =
VAR vMaxDate =
    MAX ( 'Date'[Date] )
VAR vMonths =
    CALCULATETABLE (
        DISTINCT ( 'Date'[MonthInCalendar] ),
        FILTER (
            ALL ( 'Date'[Date] ),
            'Date'[Date] <= vMaxDate
        )
    )
VAR vSummary =
    ADDCOLUMNS (
        vMonths,
        "cResult",
            VAR vODCumulative =
                CALCULATE (
                    SUM ( Cashflow[Amount] ),
                    Cashflow[Type] = "FC",
                    FILTER (
                        ALL ( 'Date'[Date] ),
                        'Date'[Date] <= vMaxDate
                    )
                )
            VAR vCashCost =
                CALCULATE (
                    SUM ( CashCost[Cash Cost] )
                )
            VAR vResult = vODCumulative - vCashCost
            RETURN
                vResult
    )
RETURN
    SUMX (
        FILTER (
            vSummary,
            [cResult] > 0
        ),
        [cResult]
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@Antmkjr  Finally got back to this one.  Here is the final measure that works and is much faster.

 

NewMeasure3 =
VAR vMaxDate =
    MAX ( 'Date'[Date] )
VAR vMonths =
    CALCULATETABLE (
        SUMMARIZE (
            'Date',
            'Date'[MonthInCalendar],
            "cThisMaxDate"MAX ( 'Date'[Date] )
        ),
        FILTER (
            ALL ( 'Date'[Date] ),
            'Date'[Date] <= vMaxDate
        )
    )
VAR vSummary =
    ADDCOLUMNS (
        vMonths,
        "cResult",
            VAR vODCumulative =
                CALCULATE (
                    SUM ( Cashflow[Amount] ),
                    Cashflow[Type] = "FC",
                    FILTER (
                        ALL ( 'Date'[Date] ),
                        'Date'[Date] <= [cThisMaxDate]
                    )
                )
            VAR vCashCost =
                CALCULATE (
                    SUM ( CashCost[Cash Cost] )
                )
            VAR vResult = vODCumulative - vCashCost
            RETURN
                vResult
    )
RETURN
    SUMX (
        FILTER (
            vSummary,
            [cResult] > 0
        ),
        [cResult]
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Brilliant you are!

lbendlin
Super User
Super User

What is your expected outcome? Do you want to add up all the EW values for the current and prior months?

Expected result:

15.PNG

 

@lbendlin @amitchandak @mahoneypat 

any help on this is highly appreciated

Hi Anu

 

I have the same problem... Has anyone helped?

 

Acumulado dúvida.PNG

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.