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
giroldoale
Helper I
Helper I

Switch Issue

Hello everyone!

I would like to learn how to use the Switch function, from a logical point of view it seems to me to be easy but obviously I didn't understand something.

I'll try to compose the tipical case

 

LUT_ANA

I create in PBI a table with 1 column having N rows

Attribute
Quantity
Value
Cost

 

DATA_TAB
I then have a data table as follows

Art.CodeQuantityValueCost
A23312123123121231234
B1231313441412
C215621
............

 

My goal is to create a selector that allows me in a Chart, for example, to display the Quantity or Cost or Value.

What  I 've done:
1- I created a "Slicer" element with LUT_ANA [Attribute] value --> with the aim of being able to select 1 of the 3 attributes.
2- I want to create a measure to be plotted which provides me the values of Quantity or Cost or Value respectively depending on which option is flagged in the point 1. In my logic I tried to insert the measure in DATA_TAB but it doesn't work with the following code.

 

 

'Version1

Value = SWITCH(ALLSELECTED(LUT_ANA[Attributo] ),

"Quantità",CALCULATE(SUM(DATA_TAB[Quantità])),

"Valore",CALCULATE(SUM(DATA_TAB[Valore])),

"Costo",CALCULATE(SUM(DATA_TAB[Costo])),)

'Version2

Value = SWITCH( 
TRUE (),

LUT_ANA[Attributo] = "Quantità",CALCULATE(SUM(DATA_TAB[Quantità])),

LUT_ANA[Attributo] = "Valore",CALCULATE(SUM(DATA_TAB[Valore])),

LUT_ANA[Attributo] = "Costo",CALCULATE(SUM(DATA_TAB[Costo])))

 

 

Can someone help me?

1 ACCEPTED SOLUTION
1 REPLY 1

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.