I have created a dashboard with a SWITCH
that can allows me to change one table column from USD to CHF.
the goal was to try to avoid Bookmarks which I hate.
But I don't like the solution because I had to create 2 useless metrics:
Cost_in_Dollars = SUM('Currency'[costInPricingCurrency])
Cost_in_Francs = SUM('Currency'[costInBillingCurrency])
These ae just metrics that reproduce the exact same columns for no reason!
And after that I was able to create the Switch:
Selected Name =
SWITCH (
SELECTEDVALUE ( Option[Name] ),
"Dollars", [Cost_in_Dollars],
"Francs", [Cost_in_Francs])
This because the switch wouldn't allow me to use the columns [costInPricingCurrency]
and [costInBillingCurrency]
directly.
Why in the hell the switch doesn't work if I use:
Selected Name =
SWITCH (
SELECTEDVALUE ( Option[Name] ),
"Dollars", [costInPricingCurrency],
"Francs", [costInBillingCurrency])
So the code is overall working.
I just want to understand why do I have to create a metrics instead of using the column directly.
I find this very stupid.
Can you explain, please?
In DAX, IF
and SWITCH
can only return a scalar value, they can't return tables or columns.
You could change it to:
Selected Name =
SWITCH (
SELECTEDVALUE ( Option[Name] ),
"Dollars", SUM('Currency'[costInPricingCurrency]),
"Francs", SUM('Currency'[costInBillingCurrency])
)