If/esleif/else is one of the the most used functions in Tableau calculation and unfortunately, it can not be applied verbatim in Power BI to achieve the same goal. The equivalent function in Power BI DAX language is the Switch() function and it works especially well on multiple scenarios, it can be used to convert either if/elseif/else statement of possibly case/when query in Tableau.
Using the super store dataset, let’s build a simple base table in Tableau.
Then create a simple calculation to measure profitability using if-elseif-else statement.
Now drag and drop profitability to the row column, can also add to the color marks card to make it more apparent.
Now let’s create the same thing in Power Bi, starting with the same base table.
Notice the numbers have a decimal place since Tableau automatically convert them to integer while Power bi keep them as is, but this is not what we need to worry about for this post, we’ll skip the changing data type part and focus on recreating the calculation.
You can choose to create a calculated column or a measure, because I’d like it to be dynamic and change based on different level of granularity, I’ll create a measure using the Swtich function, and it does the same thing as what we did in Tableau. You can take the first argument as if, second as else if, and last “loss” as else , it is that simple.
Then drag it to the table, we get the same result despite slightly different formatting .
Tableau automatically aggregate same value of each level while PBI table does not. If you prefer that Tableau view more, one workaround is to change the table to a matrix and click on that double headed arrow button to expand all down one level.
You can expand more than one level depending on the hierarchies you have. In our case, there is only one level so that button is greyed out after on click.
And because it is a measure that makes dynamic evaluation, we can clearly see the profitability is different on an order level or product level, for Order CA-2020-117964. It is profitable as an order but has a product that is at loss. Power BI makes it easy to get this whole picture visibility.