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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TrevLc
Advocate I
Advocate I

DAX help to calculate measure remaining forecast

Hi, I am struggling to work out a calulation.

Basically I need remaining forecast per "parent project"

In the example data below, firstly I have cumulative amounts only in my source, which is confusing me.

I also have actuals and forecasts in one column.

I can calculate actuals and forecast per project, but remaining forecast for the parent project is getting me. (especially the "total row")

So, for example, Parent Project "A" has 2 sub projects "Fix roads" and "build trains"

Fix roads has remaining forecast of 50 (latest month forecast minus previous month actuals)

build trains has remaining forecast 80 (latest month forecast minus previous month forecast (not this project does not have previous month actuals - plenty of projects dont))

I want to show total remaining forecast of 130 (80 + 50 ) for parent project A, but it is calculating incorrectly.

I show my data on a table visualisation per parent project.

Here is some example data:

ParentProjectVersionDateCumulative Amount
AFix roadsActuals1/04/2023100
AFix roadsActuals1/05/2023150
AFix roadsForecast1/06/2023200
Abuild trainsForecast1/05/202380
Abuild trainsForecast1/06/2023160
BNew BikesActuals1/05/2023100
BNew BikesForecast1/06/2023120

Appreciate your help

 

1 ACCEPTED SOLUTION

That is a rather unfortunate way of trying to displ;ay your data.  I am sure this will lead to user confusion.  (I don't agree with summarizing the cumulative values, for example).

 

Here is the modified measure.

 

 

Remaining Forecast =
VAR a =
    SUMMARIZE(
        'Table',
        [Parent],
        [Project],
        [Date],
        "ca", SUM( [Cumulative Amount] )
    )
VAR b =
    ADDCOLUMNS(
        a,
        "md", CALCULATE( MAX( 'Table'[Date] ), REMOVEFILTERS( 'Table'[Date] ) )
    )
VAR c =
    ADDCOLUMNS(
        b,
        "pd",
            VAR md = [md]
            RETURN
                CALCULATE(
                    MAX( 'Table'[Date] ),
                    'Table'[Date] < md
                )
    )
VAR d =
    ADDCOLUMNS(
        c,
        "pda",
            VAR pd = [pd]
            RETURN
                IF(
                    [Date] = [md],
                    [ca]
                        - CALCULATE(
                            SUM( 'Table'[Cumulative Amount] ),
                            'Table'[Date] = pd
                        )
                )
    )
RETURN
    SUMX( d, [pda] )

 

 

 

 

 

 

View solution in original post

6 REPLIES 6
TrevLc
Advocate I
Advocate I

Thanks so much.

It works (although I don't completely understand why).

However, if I add date into the table, it doesn't work.

I only want to see the latest remaining forecast (previous forecasts are no longer relevant)

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Thank you.

The dataset is per the original question, and the outcome is very similar to what you have already shown. I have mocked up what I expect below.

Appreciate your help.

TrevLc_0-1689207566524.png

 

That is a rather unfortunate way of trying to displ;ay your data.  I am sure this will lead to user confusion.  (I don't agree with summarizing the cumulative values, for example).

 

Here is the modified measure.

 

 

Remaining Forecast =
VAR a =
    SUMMARIZE(
        'Table',
        [Parent],
        [Project],
        [Date],
        "ca", SUM( [Cumulative Amount] )
    )
VAR b =
    ADDCOLUMNS(
        a,
        "md", CALCULATE( MAX( 'Table'[Date] ), REMOVEFILTERS( 'Table'[Date] ) )
    )
VAR c =
    ADDCOLUMNS(
        b,
        "pd",
            VAR md = [md]
            RETURN
                CALCULATE(
                    MAX( 'Table'[Date] ),
                    'Table'[Date] < md
                )
    )
VAR d =
    ADDCOLUMNS(
        c,
        "pda",
            VAR pd = [pd]
            RETURN
                IF(
                    [Date] = [md],
                    [ca]
                        - CALCULATE(
                            SUM( 'Table'[Cumulative Amount] ),
                            'Table'[Date] = pd
                        )
                )
    )
RETURN
    SUMX( d, [pda] )

 

 

 

 

 

 

That is perfect.

Thanks so much.

I won't be showing cumulative $ in my report, I was just showing it in my screenshot.

lbendlin
Super User
Super User

lbendlin_0-1689126604573.png

see attached

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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