cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Checkers111
Helper III
Helper III

Tricky IF DAX Formula

Hi Experts

 

I want to do the following as a either a if or Switch in a calculated column...

 

If (RTT[Actual_Weeks_Waiting] < 18, "Under 18",
If (RTT[Actual_Weeks_Waiting] >=18, "18+",
If (RTT[Actual_Weeks_Waiting] >=52, "52+",
If (RTT[Actual_Weeks_Waiting] >=72, "72+",
If (RTT[Actual_Weeks_Waiting] >=72, "78+",blank())))))
 
the above only returns back Under 18 and 18+
18+ should sum from 18 onwards to max value fine
52+ should some only values from 52 onwards to max and so on
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Checkers111,

 

Try this calculated column:

 

CalculatedColumn =
SWITCH (
    TRUE,
    RTT[Actual_Weeks_Waiting] >= 78, "78+",
    RTT[Actual_Weeks_Waiting] >= 72, "72+",
    RTT[Actual_Weeks_Waiting] >= 52, "52+",
    RTT[Actual_Weeks_Waiting] >= 18, "18+",
    RTT[Actual_Weeks_Waiting] < 18, "Under 18",
    BLANK ()
)




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

Proud to be a Super User!




View solution in original post

7 REPLIES 7
Shaurya
Memorable Member
Memorable Member

Hi @Checkers111,

 

The problem statement that you have requires you to check for a range instead of checking if it is greater than a particular number. A number like 14 will result "Under 18" but since your second condition is >18, anything that is more than 18 (25, 53, 73, 79) will statisfy that condition and you will get "18+". The rest of the conditions in your code will never even be checked.

 

You should write the code for checking the ranges like this:

 

Category = SWITCH(TRUE,
'Table'[Values]<18, "Under 18",
'Table'[Values]>=18 && 'Table'[Values]<52, "18+",
'Table'[Values]>=52 && 'Table'[Values]<72, "52+",
'Table'[Values]>=72 && 'Table'[Values]<78, "72+")

 

Result:

 

Screenshot 2022-10-07 182212.jpg

 

Did I answer your question? Mark this post as a solution if I did!

DataInsights
Super User
Super User

@Checkers111,

 

Try this calculated column:

 

CalculatedColumn =
SWITCH (
    TRUE,
    RTT[Actual_Weeks_Waiting] >= 78, "78+",
    RTT[Actual_Weeks_Waiting] >= 72, "72+",
    RTT[Actual_Weeks_Waiting] >= 52, "52+",
    RTT[Actual_Weeks_Waiting] >= 18, "18+",
    RTT[Actual_Weeks_Waiting] < 18, "Under 18",
    BLANK ()
)




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

Proud to be a Super User!




@Checkers111,

 

I looked at your other post and noticed a missing close parenthesis at the end.





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

Proud to be a Super User!




Hi - even with that corrected its still not returning back the correct result

Excellent sir worked.......

@Checkers111,

 

Glad to hear it worked. By the way, you can remove the BLANK() argument since it will return BLANK if none of the conditions are met.





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

Proud to be a Super User!




Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors