Pdata
Pdata

Reputation: 31

if then if .. else if Tableau to Power BI

I have a tableau report and trying to move things into Power BI. I have a scenario where there is a lot of "IF THEN IF" situations as shown in example


IF [SYSTEM] == "ABC" 
    THEN [Result Flag]
ELSEIF [SYSTEM] == "XYZ" THEN
        IF [Option] == 'HIGH'
        AND [Activity] == 'Add' THEN
            IF [Add Indicator] == "Yes" THEN "GA"
            ELSEIF [Name] == "Add 1" 
                OR [Name] == "Add 2" 
                THEN "Not Eligible"
            ELSE [Result Flag]
            END
    ELSEIF [Option] == 'Low' THEN 
            "2019"
        ELSE "Not Eligible"
    END
ELSE

In Power BI, we have IF and SWITCH functions but they support "IF THEN ELSE" situation and in my scenario, I have lot of "IF THEN IF" situation. I know Power BI DAX IF and SWITCH Function can handle it but when there are lot of values in the condition(Name field in above example) it is little cumbersome. Is there any better way to handle it?

Appreciate all your help!

Upvotes: 0

Views: 1184

Answers (1)

Alexis Olson
Alexis Olson

Reputation: 40234

IF THEN IF... are nested IF statements and ELSEIF can be handled with SWITCH ( TRUE (), ... ).

There are a ton of possible variations on exactly how to implement this. Here's one as an example:

SWITCH (
    [SYSTEM],
    "ABC", [Result Flag],
    "XYZ",
        SWITCH (
            TRUE (),
            [Option] = "High" && [Activity] = "Add",
                SWITCH (
                    TRUE (),
                    [Add Indicator] = "Yes", "GA",
                    [Name] IN { "Add 1", "Add 2" }, "Not Eligible",
                    [Result Flag]
                ),
            [Option] = "Low", "2019",
            "Not Eligible"
        )
)

Upvotes: 3

Related Questions