Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Trying to figure ou a SWITCH for a calculated column

Here is my structure.

 

talleslessa_0-1613132954516.png

Here is my "setup varejista" table

talleslessa_1-1613133026604.png

 

What I am trying to do :

 

Create a calculated column ("N5MP") in my product table that checks the setup varejista[#N] and calculates the field based on its value. And here is my product table structure:

 

talleslessa_0-1613133569089.png

 

Here is what I came up with so far, but it does not work. it always returns the else case of the switch

 

Filtro N5MP = VAR catmax = SELECTEDVALUE('Setup Varejista'[#N]) RETURN
SWITCH(catmax,
1,
(IF(
CALCULATE([Venda MP],ALLEXCEPT(Produto,Produto[N1]))>0,
"1",
"0")),
2,
(IF(
CALCULATE([Venda MP],ALLEXCEPT(Produto,Produto[N2]))>0,
"1",
"0")),
3,
(IF(
CALCULATE([Venda MP],ALLEXCEPT(Produto,Produto[N3]))>0,
"1",
"0")),
4,
(IF(
CALCULATE([Venda MP],ALLEXCEPT(Produto,Produto[N4]))>0,
"1",
"0")),
"Rever mercadológico"
)
 

Not sure aboute the variable setting, not very good with DAX, because of the data structure I cannot acces the  "setup varejista" from the product table in order to do the calculation, So i tought agoint checking it some other way and then bringing that value to my table...

 

What am I doing wrong/ how do I do this?

 

 

 

 

 

1 REPLY 1
PaulDBrown
Community Champion
Community Champion

@Anonymous 

The problem is that there is no context for the SELECTEDVALUE expression (so it sees no value). 

Why do you need this as a Calculated column? You could easily do the calculation in a measure for a visual.





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.