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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
prakash11440278
Post Prodigy
Post Prodigy

Multiple IF Conditions in Custom Column

Hi All,

 

I am calculating Age Category DAX formula based on the Incident logged. But i want below DAX formula to be replicated in Custom Column in Query Editor for Sorting purpose. Please provide the Custom Column formula for the below calculated column.

 

Age Bucket = IF('INC Logged'[Age of Incidents]>=0 && 'INC Logged'[Age of Incidents]<30,"0-30",
IF('INC Logged'[Age of Incidents]>=30 && 'INC Logged'[Age of Incidents]<60,"30-60",
IF('INC Logged'[Age of Incidents]>=60 && 'INC Logged'[Age of Incidents]<90,"60-90",
IF('INC Logged'[Age of Incidents]>=90 && 'INC Logged'[Age of Incidents]<180,"90-180",
"180+")))
)

 

 

Thanks In Advance.

1 ACCEPTED SOLUTION
PrasanthKumar
Frequent Visitor

Hi,

 

Can you please try this custom column query: 

(if ([Age of Incidents]>=0 and [Age of Incidents]<30) then "0-30" else  if ([Age of Incidents]>=30 and [Age of Incidents]<60) then "30-60" else if ([Age of Incidents]>=60 and [Age of Incidents]<90) then "60-90" else if ([Age of Incidents]>=90 and [Age of Incidents]<180) then "90-180" else if ([Age of Incidents]>=180 and [Age of Incidents]<90) then "180+" else "")

 

Thanks,

Prasanth.C

+91 9043194307

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

IF the value in Col A and Col B is equal to 0 then it should give me 1 else 0 along with including this third condition as if A and B both are equal to 0 it should give me "NA". This is not working for me while adding a formula in new column in power BI. How do i resolve it?

 

This is the condition as per Excel formula: =IF(AND(E5=0,F5<>0),1,IF(AND(E5=0,F5=0),"na",0)). However; this is not working in Power BI.

PrasanthKumar
Frequent Visitor

Hi,

 

Can you please try this custom column query: 

(if ([Age of Incidents]>=0 and [Age of Incidents]<30) then "0-30" else  if ([Age of Incidents]>=30 and [Age of Incidents]<60) then "30-60" else if ([Age of Incidents]>=60 and [Age of Incidents]<90) then "60-90" else if ([Age of Incidents]>=90 and [Age of Incidents]<180) then "90-180" else if ([Age of Incidents]>=180 and [Age of Incidents]<90) then "180+" else "")

 

Thanks,

Prasanth.C

+91 9043194307

Anonymous
Not applicable

Hi All,

 

Thanks @PrasanthKumar for this.

 

I've done something similar but now I need to build on it, replacing the values with parameters, so the client can edit the thresholds for each band. So based on the example below, my script looks like this:

 

CustomColumn = 

(if ([Age of Incidents]>=#"Parameter1" and [Age of Incidents]<#"Parameter2") then "0-30" else  if ([Age of Incidents]>=#"Parameter3" and [Age of Incidents]<#"Parameter4") then "30-60" else "")

 

... and so on. Error reads:  The following syntax error occurred during parsing: Invalid token line 2, offset 26, #.

 

Any help would be gratefully received.

 

Thanks,

Kevin

 

 

Hi PrasanthKumar,

 

Its Working. Thanks for your help....Man Happy

Cool..always welcome..!!! Have a good day..!!
PrasanthKumar
Frequent Visitor

Hi,

 

Can you please try this custom column query :

(if ([Age of Incidents]>=0 and [Age of Incidents]<30) then "0-30" else  if ([Age of Incidents]>=30 and [Age of Incidents]<60) then "30-60" else if ([Age of Incidents]>=60 and [Age of Incidents]<90) then "60-90" else if ([Age of Incidents]>=90 and [Age of Incidents]<180) then "90-180" else if ([Age of Incidents]>=180 and [Age of Incidents]<90) then "180+" else "")

 

Please let me know whether you got solution or not.

 

Thanks,

Prasanth.C

+91 9043194037

Anonymous
Not applicable

If you are looking for sorting only then You can do the sorting in the visuals/ data view also.

 

Thanks
Raj

Hi Rajendran, Thanks for your reply.
I believe we cannot sort the data based on the calculated column created in PBI Desktop and the format of the data type is not interger. We can sort the data based on numerical values, that can be done by adding new conditional column in query editor. I tried to create it but multiple conditions not possible using conditional column. If possible can you please provide the custom column formula for the provide calculated column.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.