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
dpombal
Post Patron
Post Patron

Cumulative Amount sum Actual + Forecast based on a date

Hi, all I have a dax question regarding following calculation

 

 

I have 1 actual transactions table

customer_id  amount_actual  date_transaction_actual

11001/01/2016
12001/01/2017
25001/04/2016
24001/05/2017
26001/08/2017

 

 

2. ) And an identical forecast transactions table

 

customer_id amount_forecast date_transaction_forecast

1501/04/2017
11501/01/2018
23501/03/2017
22501/05/2018

 

3. ) And a Forecast_updates table with a line for each customer

 

 

customer_id  forecast_update

101/01/2018
231/12/2017

 

I need to calculate a cumulative sums from fist date until forecast date from sum amount of actual table and after forecast update date , accumulate to prior amount the amount transactions from forecast table.

 

Example for customer 1

 

DATA ACTUAL

 

1 January 2016 --> 10 ---> Accum (10)

1 January 2017 --> 20 ---> Accum (10+20=30)

 

 

DATA FORECAST

1 April 2017 --> 5 ---> Do not use becasue 1 April 2017 is < Forecast update for customer 1 , (01/01/2018)

1 January 2018 --> 15 ---> Accum (10+20+15 =45)

 

 

// initial measures

actual_amount = SUM(actual_transactions[amount_actual])
forecast_amount = SUM(forecast_transactions[amount_forecast])



// cumulative all

cumulative_amount_actual = CALCULATE([actual_amount];FILTER(ALL('Calendar'[Date]);'Calendar'[Date] <= MAX('Calendar'[Date])))

cumulative_amount_forecast = CALCULATE([amount_forecast];FILTER(ALL('Calendar'[Date]);'Calendar'[Date] <= MAX('Calendar'[Date])))

 

// chances using a custom date should be changed by  table date

cumulative_amount_mixed_v2 = IF(MAX('Calendar'[Date]) < DATE(2018;1;1)
                              ;CALCULATE([actual_amount];FILTER(ALL('Calendar'[Date]);'Calendar'[Date] < DATE(2018;1;1) ))
                              ;CALCULATE([forecast_amount];FILTER(ALL('Calendar'[Date]);'Calendar'[Date] >= DATE(2018;1;1) ))
                              )

 

Link to powerbi pbix file here https://1drv.ms/u/s!Am7buNMZi-gwkCu4GDiY1wXwWU8w

1 ACCEPTED SOLUTION

@dpombal,

 

Change it as follows.

Measure =
VAR d =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR t =
    UNION (
        ALLSELECTED ( actual_transactions ),
        FILTER (
            ALLSELECTED ( forecast_transactions ),
            forecast_transactions[date_transaction_forecast]
                >= RELATED ( Forecast_Updates[forecast_update] )
        )
    )
RETURN
    SUMX (
        FILTER ( t, actual_transactions[date_transaction_actual] <= d ),
        actual_transactions[amount_actual]
    )
Community Support Team _ Sam Zha
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

7 REPLIES 7
v-chuncz-msft
Community Support
Community Support

@dpombal,

 

You may refer to the measure below.

Measure =
VAR d =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR d2 =
    SELECTEDVALUE ( Forecast_Updates[forecast_update] )
VAR t =
    UNION (
        ALLSELECTED ( actual_transactions ),
        CALCULATETABLE (
            ALLSELECTED ( forecast_transactions ),
            forecast_transactions[date_transaction_forecast] >= d2
        )
    )
RETURN
    SUMX (
        FILTER ( t, actual_transactions[date_transaction_actual] <= d ),
        actual_transactions[amount_actual]
    )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-chuncz-msft  this is a quite good solution however it only works when a customer is selected

 

Selecting customer 1  Works perfect--> 45 is final amount

customer 1 selected.PNG

 

Selecting customer2  Works perfect 175 is final amount

 

customer 2 selected.PNG

 

 

Without selections, the behaviour should be the same (45 +175 = 220) Correct and not total amount (260)

 

 

No selections.PNG

 

Updated report here

https://1drv.ms/u/s!Am7buNMZi-gwkCu4GDiY1wXwWU8w

 

 

 

Regards

@dpombal,

 

Change it as follows.

Measure =
VAR d =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR t =
    UNION (
        ALLSELECTED ( actual_transactions ),
        FILTER (
            ALLSELECTED ( forecast_transactions ),
            forecast_transactions[date_transaction_forecast]
                >= RELATED ( Forecast_Updates[forecast_update] )
        )
    )
RETURN
    SUMX (
        FILTER ( t, actual_transactions[date_transaction_actual] <= d ),
        actual_transactions[amount_actual]
    )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi friend, just one final question, if tables haven't same number of fields and in in different positions how do you adapt the union statement,  Selectcolumns should be used?

@dpombal,

 

Yes, you got it.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

thanks will try this solution looks complex, let me understand it, thanks in advance

dpombal
Post Patron
Post Patron

customer 1 data.PNG

 

 

 

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.