Forum Discussion
Using SWITCH in a table to evaluate only one row at a time
Hi, so we're trying to visualize changes in a table by adding little arrows, indicating whether an item has moved up or down since yesterday. We have a measure called #arrow that is supposed to indicate whether the arrow should point up, down or sideways. But the arrow always points up, and we suspect this is because the code evaluates the whole table, not just the one row it's on.
The strange thing is that #Test, which is also a measure, does show the correct value for just the one row. We can't figure out why it acts for one row for #Test, but for the entire table for #arrow. We've tried SELECTEDVALUE, VALUES, and SUM for #arrow.
#Test = SUM(X[DeltaRang])#arrow =
SWITCH(
TRUE(),
SUM(X[DeltaRang]) < 0, UNICHAR(9207), // Negativ
SUM(X[DeltaRang]) = 0, UNICHAR(9205), // Null
SUM(X[DeltaRang]) > 0, UNICHAR(9206), // Positiv
UNICHAR(9210)
)
Help please?
5 Replies
- johnt75
Super User
I think that this is a bug in Power BI. When I run the below code either in DAX Query View in Power BI Desktop, or in DAX Studio connected to a semantic model in the service, I get output showing all the codes with the same symbol. When I run in on dax.do ( https://dax.do/zA2kV4Detv6kqx/ ) I get the correct results.
Its probably worth raising a bug report with Microsoft support.
- bookhouseboy
Helper I
That's discouraging... but thank you for going to that effort!
- bookhouseboy
Helper I
And Microsoft support says they cannot replicate the issue. Oh well.
- bhanu_gautam
Super User
bookhouseboy , Try using
#arrow =
SWITCH(
TRUE(),
SELECTEDVALUE(X[DeltaRang]) < 0, UNICHAR(9207), // Negative
SELECTEDVALUE(X[DeltaRang]) = 0, UNICHAR(9205), // Null
SELECTEDVALUE(X[DeltaRang]) > 0, UNICHAR(9206), // Positive
UNICHAR(9210)
)- bookhouseboy
Helper I
Thanks but, no, we tried that -- no change. ☹️