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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
PMR18
New Member

Multiple Conditions Power Query

Hi folks,

 

Hope someone can help me with this...

 

I need a column with multiple conditions but can´t figure it out if it is posible.

 

1. If Bank is empty and Promo starts with "P BEN" else "SAB00" then "CRN00" but...

2. If Bank is empty and Promo starts with "P ALT" else "SAB01" then "CRN01" but...

3. If Bank is empty and Promo starts with "P AÑO" else "SAB02" then "CRN02" but...

Other way could be 

 

1. If Bank is empty and Company "A" and Promo starts with "P BEN" else "SAB00" then "CRN00" but...

2. If Bank is empty and Company "B" and Promo starts with "P ALT" else "SAB01" then "CRN01" but...

3. If Bank is empty and Company "C" and Promo starts with "P AÑO" else "SAB02" then "CRN02"

 

Thanks in advance for your help.

1 ACCEPTED SOLUTION
dufoq3
Community Champion
Community Champion

Hi @PMR18, your request doesn't make sense to me but you can inspire by this:

 

Result

dufoq3_0-1717145838124.png

let
    TableData = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRClBwcvVzdHRUitWJVoLxnZycwHwXVzewkKNPiLOzM5ISJycXFxcEHyjv6uqKJO/lDea4e3hC5A9P9EdSDebFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Bank = _t, Promo = _t]),
    TableHelper = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WClBwcvVT0lEKdnQyMFCK1QGJOPqEQEUMYSKHJ/pDhYyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]),
    ReplaceBlankToNull = Table.TransformColumns(TableData, {}, each if Text.Trim(_) = "" then null else _),
    Ad_PromoHelper = Table.AddColumn(ReplaceBlankToNull, "PromoHelper", each Text.Start([Promo], 5), type text),
    MergedQueries = Table.NestedJoin(Ad_PromoHelper, {"PromoHelper"}, TableHelper, {"A"}, "TableHelper", JoinKind.LeftOuter),
    ExpandedTableHelper = Table.ExpandTableColumn(MergedQueries, "TableHelper", {"B"}, {"B"}),
    Ad_FinalColumn = Table.AddColumn(ExpandedTableHelper, "FinalColumn", each if [Bank] = null then [B] else null, type text)
in
    Ad_FinalColumn

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

3 REPLIES 3
dufoq3
Community Champion
Community Champion

Hi @PMR18, you can edit or add more conditions here:

 

dufoq3_2-1717428386917.png

 

Result

dufoq3_3-1717428409887.png

 

let
    TableData = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs5NLCpR0lFyBGJ/JwVHnxDXID/HEM8wV6VYHYQ0dln/3NQ8oIwTEAcoOLn6OUYEI4uDhV2CgjDEQOa4umIII5ngkVoJFHIG4mBXZyQRuHagobEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, #"Bank Name" = _t, Promo = _t]),
    TableHelper = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs5NLCpR0lHyd1Jw9AkBMoIdnRQMDAyVYnWilfxzU/OAQgEKTq5+cCkjsJRHaiVYBlmTsVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, #"Promo Text" = _t, SAB = _t]),
    ReplaceBlankToNull = Table.TransformColumns(TableData, {}, each if Text.Trim(_) = "" then null else _),
    Ad_PromoHelper = Table.AddColumn(ReplaceBlankToNull, "PromoHelper", each Text.Start([Promo], 5), type text),
    MergedQueries = Table.NestedJoin(Ad_PromoHelper, {"Company"}, TableHelper, {"Company"}, "TableHelper", JoinKind.LeftOuter),
    ExpandedTableHelper = Table.ExpandTableColumn(MergedQueries, "TableHelper", {"Promo Text", "SAB"}),
    Ad_FinalColumn = Table.AddColumn(ExpandedTableHelper, "FinalColumn", each
            if [Bank Name] = null and [PromoHelper] = [Promo Text] then [SAB] else Text.Replace([SAB], "SAB", "CRN"), type text),
    RemovedColumns = Table.RemoveColumns(Ad_FinalColumn,{"PromoHelper", "Promo Text", "SAB"})
in
    RemovedColumns

 

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

PMR18
New Member

Hi @dufoq3,

 

Thanks for the quick answer.

 

The request was a bit confusing.

Lets see if it is easier to understand.

 

The image below is the normal table.

Normal Table.PNG

  
And the image below is the expected result.

Result.PNG

 

I was trying to get the expected result in Power Query.  

 

The conditions are:

1) If the company Smart has the Bank Name empty and the Promo text starts with OB ALT the result is SAB 001 if not CRN 001.

2) If the company Omen has the Bank Name empty and the Promo text starts with P BEN the result is SAB 002 if not CRN 002.

3) If the company Hey has the Bank Name empty and the Promo text starts with P ALT the result is SAB 003 if not CRN 003.

 

Once again thank you very much for your help.

 

 

dufoq3
Community Champion
Community Champion

Hi @PMR18, your request doesn't make sense to me but you can inspire by this:

 

Result

dufoq3_0-1717145838124.png

let
    TableData = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRClBwcvVzdHRUitWJVoLxnZycwHwXVzewkKNPiLOzM5ISJycXFxcEHyjv6uqKJO/lDea4e3hC5A9P9EdSDebFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Bank = _t, Promo = _t]),
    TableHelper = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WClBwcvVT0lEKdnQyMFCK1QGJOPqEQEUMYSKHJ/pDhYyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]),
    ReplaceBlankToNull = Table.TransformColumns(TableData, {}, each if Text.Trim(_) = "" then null else _),
    Ad_PromoHelper = Table.AddColumn(ReplaceBlankToNull, "PromoHelper", each Text.Start([Promo], 5), type text),
    MergedQueries = Table.NestedJoin(Ad_PromoHelper, {"PromoHelper"}, TableHelper, {"A"}, "TableHelper", JoinKind.LeftOuter),
    ExpandedTableHelper = Table.ExpandTableColumn(MergedQueries, "TableHelper", {"B"}, {"B"}),
    Ad_FinalColumn = Table.AddColumn(ExpandedTableHelper, "FinalColumn", each if [Bank] = null then [B] else null, type text)
in
    Ad_FinalColumn

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.