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
Anonymous
Not applicable

IF formula with another if condition does not work properly

Hello Community,

I am trying to categorize the sales by using IF formula

here is the DAX code ;

Sales category = IF(Orders[Sales] < 100,
                                     "Low",
                               IF(Orders[Sales]<1000,
                                 "Medium",
                                 "Hight"
                                  )
                              )
 
however, the result is not correct. 
2020-05-16 12_49_09-learing - Power BI Desktop.png
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Anyone can help to explain why and provide some solution? 
Thank you so much
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Are you writing a calculation column or measure expression?  What you've written would work in a column, but should return an error as a measure.  Your pic looks like a table visual, so you would need to write a measure differently.  Two suggestions:

 

1. Write it using the SWITCH(TRUE(), ... approach.  See this article - https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/ .  It's a better/easier way to write nested IFs.

 

2. First calculate your result as a variable, then use it in SWITCH()

 

NewMeasure = var totalsales = SUM(Orders[Sales])

return SWITCH(TRUE(), totalsales < 100, "Low", totalsales < 1000, "Medium", "High")

 

If this solution works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

You can try this measure.

 

Total Sales = Sum(Order[Sales])

 

Sales Category =
SWITCH (
    TRUE (),
    [Total Sales] < 100"Low",
     [Total Sales] >= 100
        &&  [Total Sales] < 1000"Medium",
    "High"
)

 

Regards,

Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!!

mahoneypat
Microsoft Employee
Microsoft Employee

Are you writing a calculation column or measure expression?  What you've written would work in a column, but should return an error as a measure.  Your pic looks like a table visual, so you would need to write a measure differently.  Two suggestions:

 

1. Write it using the SWITCH(TRUE(), ... approach.  See this article - https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/ .  It's a better/easier way to write nested IFs.

 

2. First calculate your result as a variable, then use it in SWITCH()

 

NewMeasure = var totalsales = SUM(Orders[Sales])

return SWITCH(TRUE(), totalsales < 100, "Low", totalsales < 1000, "Medium", "High")

 

If this solution works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

I wrote it as a new column. Thank you  @mahoneypat  the switch measure is working perfectly.

What I don't understand is why the nested if calculated column does not work properly. Did I miss something?

Thank you

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