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
IrfanYasar
Frequent Visitor

Problem with Forecast - DAX function

I have the following problem that I unfortunately cannot solve.

In a table with actual, budget and forecast data, there are 3 forecasts per table (FC 1, FC 2 and FC 3).

If I solve the problem with a measure using an IF query, it only works in the current month - the cumulative value is not correct.

TypeMMM.JJJJValue
Actual006.202210
Budget006.202215
FC 1006.202212
FC 2006.202213
FC 3006.202215
Actual007.202220
Budget007.202222
FC 1006.202215
FC 2006.202225
FC 3007.202222
Actual008.20220
Budget008.202210
FC 1008.202210

 

 

 

var _FC1 = CALCULATE(SUM('MIK_FZG'[Value]), 'MIK_FZG'[Type] IN { "FC 1" })
var _FC2 = CALCULATE(SUM('MIK_FZG'[Value]), 'MIK_FZG'[Type] IN { "FC 2" })
var _FC3 = CALCULATE(SUM('MIK_FZG'[Value]), 'MIK_FZG'[Type] IN { "FC 3" })

return
IF(ISBLANK(_FC3), IF(ISBLANK(_FC2),_FC1,_FC2), _FC3)

 

 

--> this formula only works when viewed on a monthly basis.

Target:
Always take FC 3 for past months and only the current FC for the current month.
(Whether Measure or Calculating column or Power Query)


Anybody has any ideas or tips?

Thanks in advance for the lesson 😊

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

@IrfanYasar ,

 

Try formula like below:

M_ = 
IF (
    MAX ( 'Table'[Type] ) = "FC 1",
    SUM ( 'Table'[Value] ),
    IF (
        MAX ( 'Table'[Type] ) = "FC 2",
        SUM ( 'Table'[Value] ),
        IF (
            MAX ( 'Table'[Type] ) = "FC 3",
            SUM ( 'Table'[Value] ),
            CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[MMM.JJJJ],'Table'[Type] ) )
        )
    )
)

vhenrykmstf_0-1659520458547.png

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

8 REPLIES 8
v-henryk-mstf
Community Support
Community Support

@IrfanYasar ,

 

Try formula like below:

M_ = 
IF (
    MAX ( 'Table'[Type] ) = "FC 1",
    SUM ( 'Table'[Value] ),
    IF (
        MAX ( 'Table'[Type] ) = "FC 2",
        SUM ( 'Table'[Value] ),
        IF (
            MAX ( 'Table'[Type] ) = "FC 3",
            SUM ( 'Table'[Value] ),
            CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[MMM.JJJJ],'Table'[Type] ) )
        )
    )
)

vhenrykmstf_0-1659520458547.png

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

 

Dear Henry


Thank you very much for your answer and your suggestion!

With your formula it calculates for me "Actual" + "Budget" +"FC 1" + "FC 2" + "FC 3" (in 008.2022 only the FC 1).

006.2022 - 008.2022 = 189
008.2022 = 20

I have (unfortunately) other filters that I have inserted in the "ALLEXCEPT" so that they are drawn correctly, can it be related to this?

Best Regards,
Irfan

Hi @IrfanYasar ,

 

Yes, you can add as many filtering contexts as you want to keep in the allexcept function.

 

For more details, you can read related blog.

Managing “all” functions in DAX: ALL, ALLSELECTED, ALLNOBLANKROW, ALLEXCEPT - SQLBI


Best Regards,
Henry


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

It sums with your formula current, budget and forecast

IrfanYasar
Frequent Visitor

How could I possibly solve it in a calculating column?

amitchandak
Super User
Super User

@IrfanYasar , try like

 

var _FC1 = CALCULATE(SUM('MIK_FZG'[Value]), filter('MIK_FZG','MIK_FZG'[Type] IN { "FC 1" }))
var _FC2 = CALCULATE(SUM('MIK_FZG'[Value]), filter('MIK_FZG','MIK_FZG'[Type] IN { "FC 2" }))
var _FC3 = CALCULATE(SUM('MIK_FZG'[Value]), filter('MIK_FZG','MIK_FZG'[Type] IN { "FC 3" }))

return
IF(ISBLANK(_FC3), IF(ISBLANK(_FC2),_FC1,_FC2), _FC3)

Thanks for the quick answer, I will try it right away.

Ok, I tried it, but unfortunately it still does not calculate correctly:

FC = 15 (FC 3) + 22 (FC 3) + 10 (FC 1) = 47
--> I should get cumulated.


With your formula, I get for 008.2022 = 10
Cumulated from 006.2022 to 008.2022 = 37

 

 

 

Not sure if it works at all with a measure, as it always has a cumulative value for each FC (FC 1, 2 and 3)...

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.