cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Microsoft
Microsoft

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:

  1. If S = 1, then X = B
  2. if S = 0, then X = A - B
  3. 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:

 

X= IF(SELECTEDVALUE(F[S], -1) = 1, T[B], IF(SELECTEDVALUE(F[S], -1) = 0, T[A] - T[B], T[A]))
 
I created a slicer on top of F[S]. However, my selection is always ignored in the column X in table T. Note that there is no relationship between the two tables, since one essentially has two columns (T has A and B) and the other one only one (F has S).
 
How can I make the slicer selection stick?
Thanks!
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User IV
Super User IV

Re: Change column computation based on a slicer

@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!






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





View solution in original post

3 REPLIES 3
Highlighted
Super User IV
Super User IV

Re: Change column computation based on a slicer

@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!






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





View solution in original post

Highlighted
Microsoft
Microsoft

Re: Change column computation based on a slicer

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.

Highlighted
Super User IV
Super User IV

Re: Change column computation based on a slicer

@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!






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Helpful resources

Announcements
Super Users of the Quarter - Q2 2020

Super Users of the Quarter - Q2 2020

Who are our Super User Superstars? Who made it to the top of the leaderboards? Get the answers!

June 2020 Community Highlights

June 2020 Community Highlights

Featured community members, changes to the Community, and more! Read up on recent Power BI community news.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Kudoed Authors