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
mananthakore
New Member

DAX IF && || Statement for new Column in PowerBI Desktop

HEllo Guys,

I am preety new to this powerBI Desktop . I am trying to add new column with complex IF AND OR Statement.

I am getting 90% output from this formula, but one condition just does not seem like to working and i have no idea why?

here is the formula:

Budgeted Cost = IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "1" && vTransactionHistoryAlt_FMInc[Site]="3450" || vTransactionHistoryAlt_FMInc[Site]="3240" || vTransactionHistoryAlt_FMInc[Site]="3530" ,"1499",if(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)="1" && vTransactionHistoryAlt_FMInc[Site]="3250" || vTransactionHistoryAlt_FMInc[Site]="3580" || vTransactionHistoryAlt_FMInc[Site]="3500" || vTransactionHistoryAlt_FMInc[Site]="3310" ,"881", IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "1", "227", IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "2" && vTransactionHistoryAlt_FMInc[Site]="3450" || vTransactionHistoryAlt_FMInc[Site]="3240" || vTransactionHistoryAlt_FMInc[Site]="3530" ,"5377",IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "2" && vTransactionHistoryAlt_FMInc[Site]="3250" || vTransactionHistoryAlt_FMInc[Site]="3580" || vTransactionHistoryAlt_FMInc[Site]="3500" || vTransactionHistoryAlt_FMInc[Site]="3310" ,"3048", "262")))))

 

All my criteria is getting satisfied , except where in 5th IF statement, its keep coming with result based on 4th criteria, as if 5th IF statement does not exist.

Can you guys help it to figure it out what is wrong with 5th IF statement, its same as 1'st, 2nd and 3rd and 4th,  those are workign fine.

Thanks in advance

 

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

Hi @mananthakore,

I am not sure what is your sample data and what is your expected result.

Please use the following DAX to calculate Budgeted Cost and check if you get desired result

 

Budgeted Cost = IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "1" && (vTransactionHistoryAlt_FMInc[Site]="3450" || vTransactionHistoryAlt_FMInc[Site]="3240" || vTransactionHistoryAlt_FMInc[Site]="3530" ),"1499",

if(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)="1" && (vTransactionHistoryAlt_FMInc[Site]="3250" || vTransactionHistoryAlt_FMInc[Site]="3580" || vTransactionHistoryAlt_FMInc[Site]="3500" || vTransactionHistoryAlt_FMInc[Site]="3310") ,"881", 

IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "1", "227", IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "2" && (vTransactionHistoryAlt_FMInc[Site]="3450" || vTransactionHistoryAlt_FMInc[Site]="3240" || vTransactionHistoryAlt_FMInc[Site]="3530" ),"5377",

IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "2" && (vTransactionHistoryAlt_FMInc[Site]="3250" || vTransactionHistoryAlt_FMInc[Site]="3580" || vTransactionHistoryAlt_FMInc[Site]="3500" || vTransactionHistoryAlt_FMInc[Site]="3310" ),"3048", "262")))))

 
1.PNG

Thanks,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yuezhe-msft
Employee
Employee

Hi @mananthakore,

I am not sure what is your sample data and what is your expected result.

Please use the following DAX to calculate Budgeted Cost and check if you get desired result

 

Budgeted Cost = IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "1" && (vTransactionHistoryAlt_FMInc[Site]="3450" || vTransactionHistoryAlt_FMInc[Site]="3240" || vTransactionHistoryAlt_FMInc[Site]="3530" ),"1499",

if(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)="1" && (vTransactionHistoryAlt_FMInc[Site]="3250" || vTransactionHistoryAlt_FMInc[Site]="3580" || vTransactionHistoryAlt_FMInc[Site]="3500" || vTransactionHistoryAlt_FMInc[Site]="3310") ,"881", 

IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "1", "227", IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "2" && (vTransactionHistoryAlt_FMInc[Site]="3450" || vTransactionHistoryAlt_FMInc[Site]="3240" || vTransactionHistoryAlt_FMInc[Site]="3530" ),"5377",

IF(right(vTransactionHistoryAlt_FMInc[Last 4 Digit],1)= "2" && (vTransactionHistoryAlt_FMInc[Site]="3250" || vTransactionHistoryAlt_FMInc[Site]="3580" || vTransactionHistoryAlt_FMInc[Site]="3500" || vTransactionHistoryAlt_FMInc[Site]="3310" ),"3048", "262")))))

 
1.PNG

Thanks,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
himanshu56
Resolver II
Resolver II

Hi @mananthakore

 

It is very difficult to read your formula with several if's.

 

I would advise you to use SWITCH dax instead of IF.

 

SWITCH(
    TRUE()
    ,<boolean expression>, <result if true>
    ,<boolean expression>, <result if true>
    , ..., ...
    ,<else condition - no trues above>
)

 

To know more about how to use SWITCH please have a look at the below link:

 

https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true

 

Thanks,

Himanshu

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.