Forum Discussion
Change column computation based on a slicer
Hi,
I have a table T with two columns, A and B. Depending on a slicer (S), I would like to have a third column, X, with different values:
- If S = 1, then X = B
- if S = 0, then X = A - B
- if S is not selected, then X = A
For this, I created a new table F with a simple column S that has two values (1 and 0), and added a column to T as follows:
mdemarne add as a measure
X= VAR __s = (SELECTEDVALUE(F[S], -1) RETURN SWITCH ( __s, 1, SUM ( T[B] ) 0, SUM ( T[A] ) - SUM ( T[B] ), SUM ( T[A] ) )I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
3 Replies
- parry2k
Super User
mdemarne add as a measure
X= VAR __s = (SELECTEDVALUE(F[S], -1) RETURN SWITCH ( __s, 1, SUM ( T[B] ) 0, SUM ( T[A] ) - SUM ( T[B] ), SUM ( T[A] ) )I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
- mdemarne
Microsoft Employee
Thanks for the quick reply. What if I wanted to use the column to do min, max, sum, median, etc.? I could add a measure for each, but it feels like I could just do with a column and then add measures on top? Thanks.
- parry2k
Super User
mdemarne I don't see any value to add columns, it is going to increase the size of your model and will have a performance impact, Measures is the way to go.
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!