Forum Discussion

LauraWoods's avatar
LauraWoods
Frequent Visitor
2 years ago
Solved

Inventory Months on Hand replacing if statement with Switch

Hi    I am trying to replace this long if statment with a switch can anyone help?   MOH Forecast Count forward = Var SemenInventory =  [**bleep** Inventory Future Balance] var Predictedsales...
  • Anonymous's avatar
    Anonymous
    2 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 / 30
    

     

    Best 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.