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
evalromf
Helper I
Helper I

AND IF in conditional column

Hi,

 

I'm trying to create a new column that should be populated with a certain number based on the contents of several other columns.

 

What I'm looking for is something like this:

 

If [COUNTRY] equals Kazakhstan AND IF [COMPANY] equals Alltel, then "1"

Else If [COUNTRY] equals Kazakhstan AND IF [COMPANY] equals VIP, then "2"

 

But i cannot find such a possibility in "Add conditional column". (see picture) 

 

AddAdditonalColumn.JPG

 

 

 

 

 

 

And when I try to use the Advanced Editor, I cannot find any syntax that covers this scenario.

 

Does anyone have a solution for this?

 

 

53 REPLIES 53

@GilbertQ, YES, this solved the issue. I expect to ge to the calculations and hope everything goes well.

Thank you VERY much for your assistance on this

Regards

Rodrigo

Hi @RodrigoTXRA

 

Happy to assist and get it working for you.





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

Proud to be a Super User!







Power BI Blog

RodrigoTXRA
Helper I
Helper I

HI All

 

Not sure this is the right topic for my issue, but I have an excel cell which can have by out of 4 consonants and they are represented as follows:


F = 70

P = 80
G = 100
E = 116

I'm trying to create a DAX new measure (Trying to bring this formula from excel into Power BI) which would look into the field and transform it into a number as per above.

Would anyone know how to do this?

 

Appreciate any feedback

Regards

Rodrigo

 



 

Hi there

When you say create a DAX measure, what is the expected result from your data you posted?




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

Proud to be a Super User!







Power BI Blog

Hello again

It think that it would be something like this formula below, but the other way around, instead of transforming numbers into text, for the month, it would transform text into numbers.

 

=SWITCH([Month], 1, "January", 2, "February", 3, "March", 4, "April" , 5, "May", 6, "June", 7, "July", 8, "August" , 9, "September", 10, "October", 11, "November", 12, "December" , "Unknown month number" )

 

Any ideas?

Regards

Rodrigo

HI @GilbertQ thanks for your reply.

 

I basically need the measure to look into a field and if it finds one of those four letters, to transform it into the respective number.


something like this

Measure = IF("E", then "116", or "P", then "80", or "G" then "100", or "F" then "70"

 

I just don't know the correct syntax in Power BI to perform the above.

 

Appreciate your assistance

Regards

Rodrigo

Hi there

If you need this to be a column I would suggest making the changes in the Power Query Editor, where it is a lot easier to make the changes you require.
The reason being is that you can use functions like "contains" or looking for specific things.




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

Proud to be a Super User!







Power BI Blog

Anonymous
Not applicable

Hi,

 

I need to do an IF(AND statement that has more than 2 AND conditions e.g. 

 

= IF(AND(Table[FieldX] = "1",AND(Table[FieldY] = "2",AND(Table[FieldZ] = "1")

,"True",
"False")

 

Is this possible in PBI or am I only limited to 2 AND conditions? Is there a workaround anybody knows of?

wonga
Continued Contributor
Continued Contributor

@evalromf,

 

@KHorseman's suggestion is through Power Query or M. If you prefer DAX, you can add a calculated column by right clicking on the table you want to add the column to and click "New Column".

 

The DAX formula would be something like:

 

MeasureName =

IF(AND([COUNTRY] = "Kazakhstan", [COMPANY] = "Alltel"), 1,
    IF(AND([COUNTRY] = "Kazakhstan", [COMPANY] = "VIP"), 2, "N/A")
)

//Might need another else value, not sure

Great, this (an some other modifications from my side) helped me out. Thanks!

I'm needing something similar to this... except with adding an OR...

 

Here's my scenario:

 

I have a [Course Name] column and a [Organisation / Portfolio] column.

 

Basically,

 

If [Course Name] = "Managing Information" or "Promoting Positive Workplace Behaviour"

 

AND [Organisation / Portfolio] = "University House" or "CAVAL" ....... there is about 11 of them

 

if true ... "Exclude" and if false "Include"

 

How would I write this function?

 

Thanks for any help....

 

RayinOz

Hi there, the following will work, when in the Query Editor, click on Add Column in the ribbon and then Custom Column

 

if [Course Name] = "Managing Information" or "Promoting Positive Workplace Behaviour" 
and [Organisation / Portfolio] = "University House" or "CAVAL" then "YES"
else "No"

NOTE: The syntax for the "if" "or" "and" "then" "else" is all case sensitive.





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

Proud to be a Super User!







Power BI Blog

Hi GilbertQ,

 

I have similar query. I'm stucking in below dax formula, and getting an error - "Expressions that yield variant data-type cannot be used to define calculated columns."

 

Pls suggest me..

 

Column 2 = IF('For PwerBi'[type for TAT]="MR" && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))>8,">8Hrs",

IF('For PwerBi'[type for TAT]="MR" && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))<=8,VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays])),

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("00:30:00"),"<30Min",

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("00:30:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("01:00:00"),"30 Min - 1 Hr",

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("01:00:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("01:30:00"),"1 Hr - 1.5 Hr",

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("01:30:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("02:00:00"),"1.5 Hr - 2 Hr",

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("02:00:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("02:30:00"),"2 Hr - 2.5 Hr",

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("02:30:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("03:00:00"),"2.5 Hr - 3 Hr",

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("03:00:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("03:30:00"),"3 Hr - 3.5 Hr",

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("03:30:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("04:00:00"),"3.5 Hr - 4 Hr",

IF('For PwerBi'[type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("04:00:00"),"> 4 Hr",

IF('For PwerBi'[type for TAT]="RNW" && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))<8,"< 8 Hrs",

IF('For PwerBi'[type for TAT]="RNW" && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))>=8 && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))<16,"8 - 16 hrs",

IF('For PwerBi'[type for TAT]="RNW" && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))>=16 && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))<24,"16 - 24 hrs",

IF('For PwerBi'[type for TAT]="RNW" && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))>=24 && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))<36,"24 hrs - 36 hrs",

IF('For PwerBi'[type for TAT]="RNW" && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))>=36 && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays])),"36 hrs - 48 hrs",

IF('For PwerBi'[type for TAT]="RNW" && VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))>=48,"> 48 hrs",

IF('For PwerBi'[type for TAT]="NA","NA",VALUE(INT(24*'For PwerBi'[TAT excluding weekends_holidays]))))))))))))))))))))

Hi Board, I believe that I can post this query if i found any similar pattern of query..?? Or else, i can post new one..

Hi there

I would suggest instead of using a calculated column in the data model, do this in the Power Query Editor where you can use the Custom Column, where you can use multiple conditions.

here is my blog post explaining this: https://www.fourmoo.com/2018/11/27/multiple-conditions-for-a-conditional-column-in-power-query/




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

Proud to be a Super User!







Power BI Blog

Hi,

On your solution, it is not written how to get custom column. I got it now, its difficult me to find that. Okk..

 

As now im trying in custom column, how do i mentioned this line-

IF[Cond1]="abc" and INT(24*[TAT excluding weekends_holidays])>8, then ">8Hrs"

else if ...

INT(24*[TAT excluding weekends_holidays])>8 ??

 

Can i use INT above? Or directly like

IF[cond1]="abc" and 24*[TAT excluding weekends_holidays])>8 then ">8Hrs"

else if ...

Hi, I do some random check.

When I'm using single if condition like-

Column = IF('For PwerBi'[Cert type for TAT]="Midterm Routine" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])>8,">8Hrs","NA")

im not getting an error and output comes.

 

But, When im adding one IF condition like-

Column = IF('For PwerBi'[Cert type for TAT]="Midterm Routine" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])>8,">8Hrs",IF('For PwerBi'[Cert type for TAT]="Midterm Routine" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])<8,INT(24*[TAT excluding weekends_holidays]),"NA"))

it giving me an error - "Expressions that yield variant data-type cannot be used to define calculated columns."

 

I dont understand meaning of this error. Why it appears. Someone pls help me in this.

Hi GilbertQ, Thank You so much for sharing an answer. As well as Thanks for showing me this new website, this too help me to learn a lot.

About solution you have provided, i think that option is available in Power BI Pro option, wherein im using desktop version.

I will try with pro version. Thanks again..

Hi there

Glad we got this part working.

Could I suggest for your other issue to create a new post?

Easier to keep them separate.




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

Proud to be a Super User!







Power BI Blog

Sorry for again. Can you also guide me how do i get Power Bi Pro free login option..

Thanks. This was exactly what I needed and super helpful. Do you know of any sites where the general language for Power BI Power Query Editor is described? 

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.