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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
MikhailGG
Helper I
Helper I

Switch with Multiple Hasonevalue() gives wrong results

I have the following formula
 
Overview_Switch = switch( true(),
                                    HASONEVALUE('Data'[Region]), median('Sales_by_Region'[Total]),
                                    HASONEVALUE('Data'[Country]),median('Sales_by_Country'[Total]),
                                    HASONEVALUE('Datay'[Functional Area]), median('Sales_by_Func_Area'[Total]),
                                    HASONEVALUE('Data'[Manager]), median('Sales_by_Manager'[Total]),
                                    median('Data'[Official_Total])
)
 
The goal is essentially to feed card visual with the proper value based on choosing different values in the visuals of Region, Country, Functional Area or Manager.:
MikhailGG_0-1742588668017.png

 

However, it looks like I'm getting incorrect results if more than 1 statements in switch falls under a single value. In that case whichever statement comes first is the one that populates the card.

 

How can I change the formula to make the results accurate?

1 ACCEPTED SOLUTION
MikhailGG
Helper I
Helper I

iffiltered() insted of hasonevalue() solved the issue for me

View solution in original post

6 REPLIES 6
MikhailGG
Helper I
Helper I

iffiltered() insted of hasonevalue() solved the issue for me

Anonymous
Not applicable

Hi @MikhailGG,

 

Glad your issue has been resolved!
I suggest you to accept your own post as the solution — it will help other community members facing similar problems to find the answer faster.

 

Regards,

Vinay Pabbu

Tutu_in_YYC
Super User
Super User

The switch statement evaluate in sequence, so if the first statement is true, it will stop there.

If you need to evalute combinations of multiple statements, you might have to do something like this:

 

VAR _statement1 =  HASONEVALUE('Data'[Region])
VAR _statement2 =  HASONEVALUE('Data'[Country])
VAR _statement3 =  HASONEVALUE('Data'[Functional Area])

SWITCH(
   TRUE(),
   Statement1 && Statement2 && Statement3, Result1,
   Statement1 && Statement2, Result2,
   Statement1, Result3,
Result4
)

 

That is the problem. How can I ignore the sequence if I slice by Functional Area, but the chosen functional area has only single region and since region comes before functional area in the switch statement, I get results for region instead of functional area? Is there a different approach besides switch?

 

Each of those tables: sales_by_region, sales_by_country and etc have slightly different values for Total. They just have different weights depending on the table.

Deku
Super User
Super User

Can you share your data model, I think you're problem is modelling maxing the DAX much more complicated than it needs to be. 

 

Realistically you should 

  • Geography dimension( region and country)
  • Functional area dimension
  • Manager dimension
  • Sales fact

 

Then the measure would just be median( sales[offical_total] ) and you can slice and dice however you want.

 

Your current issue what happens if some selects filter from multiple slicers, they will likely get misleading results


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

this ☝️

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors