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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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