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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculated column multiple if conditions

I basically have four flag columns, which can either be 0 or 1. I want to create a column where if any of these columns equals 1, this created column is set to "Employed", whereas if they are all 0, it is equal to "Unemployed". I tried this formula and it is not giving me the correct results:

 

Employment = if('program'[EmpQ1_AfterExitQtr]=1,
"Employed",if('program'[EmpQ2_AfterExitQtr]=1,"Employed",if('program'[EmpQ3_AfterExitQtr]=1,"Employed",if('program'[EmpQ4_AfterExitQtr]=1,"Employed","Unemployed"))))

 

How would I go about creating this column?

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

I used this Enter Data query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wci9KTVfSUTIEYgM4jtWJVvLKz4PyDVHEnTJzcpAUG8IlQvJzUQwByYHEXeAGoVlQmpOZCjUBgWNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Employee = _t, Q1 = _t, Q2 = _t, Q3 = _t, Q4 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", type text}, {"Q1", Int64.Type}, {"Q2", Int64.Type}, {"Q3", Int64.Type}, {"Q4", Int64.Type}})
in
    #"Changed Type"

and this calculated column based on your formula:

Employment = if([Q1]=1,
"Employed",if([Q2]=1,"Employed",if([Q3]=1,"Employed",if([Q4]=1,"Employed","Unemployed"))))

Seemed to work. Perhaps your values are text instead of numbers?

 

An easier way might be to just have a calculated column like this:

 

Column = [Q1] + [Q2] + [Q3] + [Q4]

And then one like:

 

Column1 = IF([Column] > 0,"Employed","Unemployed")

You were creating this column in DAX in the data model and not in "M" in the Query Editor correct? Because the syntax for if is different in "M".

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

I used this Enter Data query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wci9KTVfSUTIEYgM4jtWJVvLKz4PyDVHEnTJzcpAUG8IlQvJzUQwByYHEXeAGoVlQmpOZCjUBgWNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Employee = _t, Q1 = _t, Q2 = _t, Q3 = _t, Q4 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", type text}, {"Q1", Int64.Type}, {"Q2", Int64.Type}, {"Q3", Int64.Type}, {"Q4", Int64.Type}})
in
    #"Changed Type"

and this calculated column based on your formula:

Employment = if([Q1]=1,
"Employed",if([Q2]=1,"Employed",if([Q3]=1,"Employed",if([Q4]=1,"Employed","Unemployed"))))

Seemed to work. Perhaps your values are text instead of numbers?

 

An easier way might be to just have a calculated column like this:

 

Column = [Q1] + [Q2] + [Q3] + [Q4]

And then one like:

 

Column1 = IF([Column] > 0,"Employed","Unemployed")

You were creating this column in DAX in the data model and not in "M" in the Query Editor correct? Because the syntax for if is different in "M".

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Actually, nevermind, turns out it is working fine, I just misread the data. Thanks.

Eh, been there! 🙂



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.