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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
AMD2183
Regular Visitor

Create new column using condition

Hi and good day members, 

 

Iam fairly new to power bi and still learning by practicing on my own. Can anybody help me on how i can create "Column D" and "Column E" using the condition in E4 and F4 respectively. I can get the idea in excel but on power query seems a lost for me. Iam expecting result as per image below.

AMD2183_2-1728910432211.png

Expected Result

AMD2183_3-1728910601415.png

 

1 ACCEPTED SOLUTION
uzuntasgokberk
Super User
Super User

Hello @AMD2183,

 

You can use below the code of Power Query.

Add a new custom column example "E".
if ([C] = "A" or [C] = "B") and [D] = "PASS" then "PASS"
else if [C] = "C" and [D] = "PASS" then "PASS"
else "FAIL"

And again add new custom column.
if ([E] = "PASS" or [E] = "PASS") and [E] = "PASS" then "PASS"
else "FAIL"

Kind Regards,
Gökberk Uzuntaş

📌 If this post helps, then please consider Accepting it as a solution and giving Kudos — it helps other members find answers faster!

🔗 Stay Connected:
📘 Medium |
📺 YouTube |
💼 LinkedIn |
📷 Instagram |
🐦 X |
👽 Reddit |
🌐 Website |
🎵 TikTok |

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @AMD2183 ,
First of all, it is clear that there is no concept of merging cells in power bi, so there should be a corresponding value for each piece of data. You can refer to the following m code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kksKMkvcFTSUQLhgMTiYqVYHWRhJyB2S8zMQRN2xlTtBDUETbUTdkOcsBvijN0lzlBDsAgjDIkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column A" = _t, ColumnB = _t, ColumnC = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Column D", each if ([ColumnB] = "A" or [ColumnB] = "B") and [ColumnC] = "Pass" then "Pass" else if [ColumnB] = "C" and [ColumnC] = "Pass" then "Pass" else "Fail"),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Column D.1", each if [ColumnC] = "Pass" then "Pass" else "Fail
"),
    #"Grouped Rows" = Table.Group(#"Added Custom1", {"Column A"}, {{"AllPass", each List.AllTrue(List.Transform([Column D], each _ = "Pass")), type logical}}),
    #"Merged Tables" = Table.NestedJoin(#"Added Custom1", {"Column A"}, #"Grouped Rows", {"Column A"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Table" = Table.ExpandTableColumn(#"Merged Tables", "Grouped Rows", {"AllPass"}),
    #"Added NewColumn" = Table.AddColumn(#"Expanded Table", "Column E", each if [AllPass] then "Pass" else "Fail"),
    #"Removed Columns" = Table.RemoveColumns(#"Added NewColumn",{"AllPass"})
in
    #"Removed Columns"

Here for Column D you use the logic you provided. For Column D.1 is the simplified logic.

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Omid_Motamedise
Super User
Super User

In power query there is no merge cell, so after loading data into power query, use fill down to replace any null value with its previous value. Then use add new column and use if as almost the same as excel with the below structure

 

 

If ....... then ........else ........


If my answer helped solve your issue, please consider marking it as the accepted solution.
uzuntasgokberk
Super User
Super User

Hello @AMD2183,

 

You can use below the code of Power Query.

Add a new custom column example "E".
if ([C] = "A" or [C] = "B") and [D] = "PASS" then "PASS"
else if [C] = "C" and [D] = "PASS" then "PASS"
else "FAIL"

And again add new custom column.
if ([E] = "PASS" or [E] = "PASS") and [E] = "PASS" then "PASS"
else "FAIL"

Kind Regards,
Gökberk Uzuntaş

📌 If this post helps, then please consider Accepting it as a solution and giving Kudos — it helps other members find answers faster!

🔗 Stay Connected:
📘 Medium |
📺 YouTube |
💼 LinkedIn |
📷 Instagram |
🐦 X |
👽 Reddit |
🌐 Website |
🎵 TikTok |

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.