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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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()

))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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