Forum Discussion
Using Switch in an If Statement
I've seen this solution, but when I try it, the table[column] name can't be added to the measure. I'm just... so confused.
I have two swtiches that are adding unicharacter up/down/null arrows that are used to display an up/down/vertical arrows. The trick is, some results are good (up arrow), while some are bad (down arrow).... (example: good is +10% increase in users, but +10% in query time is bad) I have two switch statements that work on their own, but I'd like the data to show in a single row, using the ID of known 'bad' items being measured.
The issue I'm having is the Switch DAX measure won't accept the 'table'[column] name. Just gives me the sqiggle red-line of death.
Statement
IF('HI Team Metrics Details'[MasterID] IN {"24","31","9","32"}, // if the items equal this...
SWITCH( ///use this switch
TRUE(),
[m_difference%_filter]>0, UNICHAR(11014), //up
[m_difference%_filter]<0, UNICHAR(11015), //down
[m_difference%_filter]=0, UNICHAR(11020), //side
"" //empty
),
SWITCH( //if not, use this one
TRUE(),
[m_difference%_filter]<0, UNICHAR(11014), //up
[m_difference%_filter]>0, UNICHAR(11015), //down
[m_difference%_filter]=0, UNICHAR(11020), //side
"" //empty
)
)
error: (Column does not exist)
- I tried to build another measure to use in this If Statement to filter the ID's, but I'm still not able to add the column name.
TDisco You're doing this as a measure, so you have no row context for the current value in the column. You can get the current value from that column by using SELECTEDVALUE:
IF('SELECTEDVALUE(HI Team Metrics Details'[MasterID]) IN {"24","31","9","32"}, // if the items equal this...
SWITCH( ///use this switch
TRUE(),
[m_difference%_filter]>0, UNICHAR(11014), //up
[m_difference%_filter]<0, UNICHAR(11015), //down
[m_difference%_filter]=0, UNICHAR(11020), //side
"" //empty
),
SWITCH( //if not, use this one
TRUE(),
[m_difference%_filter]<0, UNICHAR(11014), //up
[m_difference%_filter]>0, UNICHAR(11015), //down
[m_difference%_filter]=0, UNICHAR(11020), //side
"" //empty
)
)
2 Replies
- AllisonKennedyCommunity Champion
TDisco You're doing this as a measure, so you have no row context for the current value in the column. You can get the current value from that column by using SELECTEDVALUE:
IF('SELECTEDVALUE(HI Team Metrics Details'[MasterID]) IN {"24","31","9","32"}, // if the items equal this...
SWITCH( ///use this switch
TRUE(),
[m_difference%_filter]>0, UNICHAR(11014), //up
[m_difference%_filter]<0, UNICHAR(11015), //down
[m_difference%_filter]=0, UNICHAR(11020), //side
"" //empty
),
SWITCH( //if not, use this one
TRUE(),
[m_difference%_filter]<0, UNICHAR(11014), //up
[m_difference%_filter]>0, UNICHAR(11015), //down
[m_difference%_filter]=0, UNICHAR(11020), //side
"" //empty
)
)- TDiscoHelper I
That is sheer sorcery. Thank you.