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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
AivaS
Frequent Visitor

Cumulative Formula by date

Dear All,


I am been trying to workout why the Cumulative cost is not working, please see my forumal below.

 

 

 

RT Profit =
VAR MaxDate = MAX ( 'Calendar'[Date]
RETURN
    CALCULATE (
        [PROFIT M],        
        'Calendar'[Date] <= MaxDate
        ALL ('Calendar'[Date])           
    )

 

 

The results just matching the Profit by month, not cumulative.

 

Below is the table and Data view. 

Screenshot 2025-01-13 105838.pngScreenshot 2025-01-13 105854.png

 

1 ACCEPTED SOLUTION

Hi, @AivaS 
 Thank you for your prompt response.

1.You can try the following measure:

Measure = 
VAR table1 =
    SUMMARIZE(
        ALLSELECTED('summary_by_month'),
        'summary_by_month'[Date].[Month],
        "AVG",
        VAR cm = 'summary_by_month'[Date].[Month]
        VAR _averageProfit =
            CALCULATE(
                AVERAGE(summary_by_month[profit]),
                FILTER(
                    ALL(summary_by_month),
                    'summary_by_month'[Date].[Month] = cm
                )
            )
        RETURN _averageProfit,
        "INEDX1",
        SWITCH(
            'summary_by_month'[Date].[Month],
            "January", 1,
            "February", 2,
            "March", 3,
            "April", 4,
            "May", 5,
            "June", 6,
            "July", 7,
            "August", 8,
            "September", 9,
            "October", 10,
            "November", 11,
            "December", 12
        )
    )
 
VAR table2 =
    SUMMARIZE(
        table1,
        'summary_by_month'[Date].[Month],
        [INEDX1],
        "running",
        SUMX(
            FILTER(table1, [INEDX1] <= EARLIER([INEDX1])),
            [AVG]
        )
    )
 
VAR f =
    SUMX(
        FILTER(table1, [INEDX1] = MAX([INEDX1])),
        [AVG]
    )
 
VAR f1 =
    SUMX(
        FILTER(table2, 'summary_by_month'[Date].[Month] = MAX('summary_by_month'[Date].[Month])),
        [running]
    )
 
RETURN
    IF(
        ISINSCOPE('summary_by_month'[Date].[Month]),
        f1,
        f
    )

2.Here's my final result, which I hope meets your requirements.

vlinyulumsft_0-1736933279262.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
AivaS
Frequent Visitor

 

I thinkI need to add a filter in the formula? it seems then I use the "Calendar" Table, I get this resulin the table ? 
Sum of profit being a column, Profit M being a measure, RT profit is the one I amtrying to work out. 

Screenshot 2025-01-14 075640.png

Hi, @AivaS 
 Thank you for your prompt response.

1.You can try the following measure:

Measure = 
VAR table1 =
    SUMMARIZE(
        ALLSELECTED('summary_by_month'),
        'summary_by_month'[Date].[Month],
        "AVG",
        VAR cm = 'summary_by_month'[Date].[Month]
        VAR _averageProfit =
            CALCULATE(
                AVERAGE(summary_by_month[profit]),
                FILTER(
                    ALL(summary_by_month),
                    'summary_by_month'[Date].[Month] = cm
                )
            )
        RETURN _averageProfit,
        "INEDX1",
        SWITCH(
            'summary_by_month'[Date].[Month],
            "January", 1,
            "February", 2,
            "March", 3,
            "April", 4,
            "May", 5,
            "June", 6,
            "July", 7,
            "August", 8,
            "September", 9,
            "October", 10,
            "November", 11,
            "December", 12
        )
    )
 
VAR table2 =
    SUMMARIZE(
        table1,
        'summary_by_month'[Date].[Month],
        [INEDX1],
        "running",
        SUMX(
            FILTER(table1, [INEDX1] <= EARLIER([INEDX1])),
            [AVG]
        )
    )
 
VAR f =
    SUMX(
        FILTER(table1, [INEDX1] = MAX([INEDX1])),
        [AVG]
    )
 
VAR f1 =
    SUMX(
        FILTER(table2, 'summary_by_month'[Date].[Month] = MAX('summary_by_month'[Date].[Month])),
        [running]
    )
 
RETURN
    IF(
        ISINSCOPE('summary_by_month'[Date].[Month]),
        f1,
        f
    )

2.Here's my final result, which I hope meets your requirements.

vlinyulumsft_0-1736933279262.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

divyed
Super User
Super User

Hello @AivaS ,

 

Your DAX formula for calculating the cumulative profit has a small issue.

Modify your dax like below and try again :

 

RT Profit =
VAR MaxDate = MAX('Calendar'[Date])
RETURN
CALCULATE(
[PROFIT M],
FILTER(
ALL('Calendar'),
'Calendar'[Date] <= MaxDate
)
)

 

I hope this helps.

 

Cheers

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/
AivaS
Frequent Visitor

Unfortunately, it still has the same result. 

Hello @AivaS ,

 

I have tested on dummy data and it is working. I have created a measure total_Sales and I have da date table. Please replace your tables accordingly and try again

Here is my dax :

RunningTotalSales =
VAR CurrentDate =
    MAX ( Datestbl[Date] )
RETURN
    IF (
        NOT ( ISBLANK ( Measurestbl[TotalSales] ) ),
        CALCULATE ( Measurestbl[TotalSales], Datestbl[Date] <= CurrentDate ),
        BLANK ()
    )
 
divyed_0-1736841737677.png

 

I hope this helps .

Did I answer your query ? Mark this as solution if this solves your issue, kudos are appreciated.

 

Cheers.

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/
johnt75
Super User
Super User

Your RT Profit is a calculated column. Delete the column and use the same code to make a measure.

AivaS
Frequent Visitor

RT profit is a measure, 
maybe the issue is that in RT profit measure I am using Profit M, measure which is created by the following formula :

PROFIT M = AVERAGE('summary_by_month'[profit])
 
since the "profit" is a column and I needed a measure to calculate. 

Thanks for the reply from divyed and johnt75 , please allow me to provide another insight:

Hi, @AivaS 
Thanks for reaching out to the Microsoft fabric community forum.

 

The most efficient solution currently is to use visual object calculations:

1.Here is my test data:

vlinyulumsft_0-1736838497300.png

Initial visualization results:

vlinyulumsft_1-1736838497302.png

2.Click on the visual object and select visual calculation:

vlinyulumsft_2-1736838619137.png

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_3-1736838619139.png

4.For further details, please refer to:

Using visual calculations in Power BI Desktop - Power BI | Microsoft Learn

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Excellent, thank you so much. That was very easy, indeed, however, I will need to use the measure of Running Total in KPI cards, so from testing out it seems the visual calculation only works for that particular visual, and does not create a measure?

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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