Forum Discussion

Niels_T's avatar
Niels_T
Post Patron
4 years ago
Solved

IF statement won't work properly

I have written a long if statement that goes as followed:   Total Direct Unit Cost = VAR CurrencyUSD = CALCULATE(SUM('Currency Rate'[Units per EUR]),'Currency Rate'[Currency] = "USD") RETURN IF(...
  • Icey's avatar
    4 years ago

    Hi Niels_T ,

     

    Based on my understanding, try to modify your measure like so:

    Total Direct Unit Cost =
    VAR CurrencyUSD =
        CALCULATE (
            SUM ( 'Currency Rate'[Units per EUR] ),
            'Currency Rate'[Currency] = "USD"
        )
    RETURN
        IF (
            'Vendor List'[EU / Non-EU] IN { "EU" },
            SUM ( 'Stock Forecast'[Total Remaining Direct Unit Cost] ) * 1.03,
            IF (
                'Vendor List'[EU / Non-EU] IN { "non-EU (EUR)" },
                SUM ( 'Stock Forecast'[Total Remaining Direct Unit Cost] ) * 1.06,
                IF (
                    'Vendor List'[EU / Non-EU] IN { "non-EU (USD)" },
                    DIVIDE (
                        SUM ( 'Stock Forecast'[Total Remaining Direct Unit Cost] ) * 1.35,
                        CurrencyUSD
                    ),
                    IF ( ISBLANK ( SUM ( 'Stock Forecast'[Total Remaining Direct Unit Cost] ) ), 0 )
                )
            )
        )
    

     

    Or like so:

    Total Direct Unit Cost =
    VAR CurrencyUSD =
        CALCULATE (
            SUM ( 'Currency Rate'[Units per EUR] ),
            'Currency Rate'[Currency] = "USD"
        )
    RETURN
        SWITCH (
            TRUE (),
            SWITCH (
                'Vendor List'[EU / Non-EU],
                "EU", SUM ( 'Stock Forecast'[Total Remaining Direct Unit Cost] ) * 1.03,
                "non-EU (EUR)", SUM ( 'Stock Forecast'[Total Remaining Direct Unit Cost] ) * 1.06,
                "non-EU (USD)",
                    DIVIDE (
                        SUM ( 'Stock Forecast'[Total Remaining Direct Unit Cost] ) * 1.35,
                        CurrencyUSD
                    )
            ), ISBLANK ( SUM ( 'Stock Forecast'[Total Remaining Direct Unit Cost] ) ),
            0
        )
    

     

     

    Best Regards,

    Icey

     

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