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
christianfcbmx
Post Patron
Post Patron

IF Function with 3 or more posible results HELP!

This could be basic Dear Community but I need to find the way to clasify a result in 3 posibilities using "If"

 

I need to know if a x number es between 9, 16, 24.

 

ANY HELP WOULD BE SO MUCH APPRECIATED

 

My try was the following:

 

Rango* = IF('column (Chil'[TotalhoursDiff**]<= 'column (Chil'[Rango 1],"1",IF(AND('column (Chil'[TotalhoursDiff**]<='column (Chil'[Rango 2],'column (Chil'[TotalhoursDiff**]<='column (Chil'[Rango 3]),"2","3"))

 

Captura5.JPG

1 ACCEPTED SOLUTION

Hmm, that's odd, do you have <= in the formula for the second condition?

 

The general format of the IF is:

 

IF(<condition>, <if true>, <if false>)

 

So, you just keep tacking on IF statements in the <if false> area. So, if you need a fourth value, you would just tack on an IF statement where you have the 3. You can string these together indefinitely but you might want to take a look at the SWITCH statement instead of the IF statement as it will be cleaner code-wise.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

9 REPLIES 9
jthomson
Solution Sage
Solution Sage

What range of TotalhoursDiff** should produce an output of 1, 2 or 3 respectively?

Exactly...and I might need a 4° range!

 

Thank @jthomson

Greg_Deckler
Super User
Super User

You have a mystery AND in there, not sure why. Try this:

 

Rango* = IF('column (Chil'[TotalhoursDiff**]<= 'column (Chil'[Rango 1],"1",IF('column (Chil'[TotalhoursDiff**]<='column (Chil'[Rango 2],2,3))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler thats work better thank you but I have 2 last questions... what can I do when is 16:00 to keep it in range 2... because when is 16:00 goes to range 3.

 

What About if I need to add a fourth range (4)... How do I continue with the formula?

 

That would be all...hopefully you can give me a hand!!!

 

WRONG!!WRONG!!

Hmm, that's odd, do you have <= in the formula for the second condition?

 

The general format of the IF is:

 

IF(<condition>, <if true>, <if false>)

 

So, you just keep tacking on IF statements in the <if false> area. So, if you need a fourth value, you would just tack on an IF statement where you have the 3. You can string these together indefinitely but you might want to take a look at the SWITCH statement instead of the IF statement as it will be cleaner code-wise.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Pretty decent advices fellows!!!! thank you so much

Would SWITCH actually work if it's trying to compare a range of values? AFAIK it would only work with constant values, and OP's got a lot of potential constant values

Sure you could use SWITCH

 

https://community.powerbi.com/t5/Desktop/Switch-amp-Calculate-Issue/m-p/352890#M158765


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Heh, didn't think of using a variable as an intermediate step, that's nice

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.

Top Solution Authors