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
rsanyoto
Helper III
Helper III

Switch function with IF else statement

Hello all,

 

the following scenario is needed:

 

In my report i used the Measure A to be able to shown a measure when a user click on the slicer. But in this Measure A there is 2different measures that are filtered from two different columns. 
The [Growth last month]  is  using the column Occupation[Month]
The [sacked last month] is using column Occupation[NextMonth]

 

Because of this two different columns for filtering some of my Power BI charts are not filtered.

So i though i add use a IF Then else statement in Measure A to say:

 

If the [Growth last month] are clicked in the slicer then  a bar chart need to shown data based on the Occupation[Month]

and if the [sacked last month] then a bar chart need to shown data from Occupation[NextMonth]

 

Measure A =

SWITCH( TRUE(),

    VALUES('Fact Growth'[Growth Fact]) = "Growth in employees last month",'Fact Growth'[Growth last month],

    VALUES('Fact Growth'[Growth Fact]) = "Total employees sacked last month ",'Fact Growth'[sacked last month],

BLANK()

)

 

Any suggestion how i can improve/change the Measure A to add the if condition based on the two columns of Occupation tables?

 

Many thanks!

 

3 REPLIES 3
rsanyoto
Helper III
Helper III

bar chartbar chartslicer object with two measuresslicer object with two measuresOccupation[Month] filter in bar chartOccupation[Month] filter in bar chart

amitchandak
Super User
Super User

@rsanyoto , Try like

 

Measure A =

SWITCH( TRUE(),

max('Fact Growth'[Growth Fact]) = "Growth in employees last month",'Fact Growth'[Growth last month],

max('Fact Growth'[Growth Fact]) = "Total employees sacked last month ",'Fact Growth'[sacked last month],

BLANK()

)

 

or


Measure A =
sumx(values('Fact Growth'[Growth Fact]),
SWITCH( TRUE(),

max('Fact Growth'[Growth Fact]) = "Growth in employees last month",'Fact Growth'[Growth last month],

max('Fact Growth'[Growth Fact]) = "Total employees sacked last month ",'Fact Growth'[sacked last month],

BLANK()

))

hI @amitchandak ,

 

Thanks for your quick response. I have tested both of your proposals but the Bar chart that use the Measure A dont filter the right data.

fyi: this barchart uses has a default filter based on Occupation[Month]

My question to you is: is it right to keep this default filter on this barchart to let your proposals works? or should i delete Occupation[Month] on the filter visual?

Because the goal of the  measure A needs is need to be "flexible" by showing the right data when a user click on one of the measure in the slicer visual.



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.