Forum Discussion
Inventory Months on Hand replacing if statement with Switch
- Anonymous2 years ago
Hi LauraWoods ,
Please try below dax formula:
MOH Forecast Count forward = VAR SemenInventory = [**bleep** Inventory Future Balance] VAR PredictedsalesMOH = [Predicted sales MOH] VAR Rev = { PredictedsalesMOH, CALCULATE ( PredictedsalesMOH, DATEADD ( '130 Date'[DateKey], 1, MONTH ) ), CALCULATE ( PredictedsalesMOH, DATEADD ( '130 Date'[DateKey], 2, MONTH ) ), ... CALCULATE ( PredictedsalesMOH, DATEADD ( '130 Date'[DateKey], 14, MONTH ) ) } VAR CumulativeRev = ADDCOLUMNS ( GENERATESERIES ( 1, 14, 1 ), "CumRev", CALCULATE ( SUMX ( TOPN ( [Value], Rev ), [Value] ) ) ) VAR Result = SWITCH ( TRUE (), SemenInventory < LOOKUPVALUE ( CumulativeRev[CumRev], CumulativeRev[Value], 1 ), ROUNDUP ( SemenInventory / ( LOOKUPVALUE ( CumulativeRev[CumRev], CumulativeRev[Value], 1 ) / 30 ), 0 ) + 30, SemenInventory < LOOKUPVALUE ( CumulativeRev[CumRev], CumulativeRev[Value], 2 ), ROUNDUP ( ( SemenInventory - LOOKUPVALUE ( CumulativeRev[CumRev], CumulativeRev[Value], 1 ) ) / ( LOOKUPVALUE ( CumulativeRev[CumRev], CumulativeRev[Value], 2 ) / 30 ), 0 ) + 60, ... SemenInventory < LOOKUPVALUE ( CumulativeRev[CumRev], CumulativeRev[Value], 14 ), ROUNDUP ( ( SemenInventory - LOOKUPVALUE ( CumulativeRev[CumRev], CumulativeRev[Value], 13 ) ) / ( LOOKUPVALUE ( CumulativeRev[CumRev], CumulativeRev[Value], 14 ) / 30 ), 0 ) + 420, 450 ) RETURN Result / 30Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Have you tested this? I don't think it's going to work because at the start the variables are storing the evaluated measure and then the variable is used in different calculate statements but once the measure is evaluated, it is a fixed amount so they are all going to return the same amount.
Do you want to show some sample data and state what you are trying to do? There's bound to be a better way.
--
And please, to spare your blushes, change the name of that variable. It's very funny but even the powerbi forum website beeped it out!
Hi Apologies I have not tested this out yet. I will share some sample data for what i would like the outcome to be. I didnt even think of the name of the variable it is the business we work in apologies it bioengineering and this is the product we have.