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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
ImaKickUrBut
Frequent Visitor

Add column to Merged Query when sub query contains text

Hello! I'm very new to PBI & need some guidance please. 

 

I have 2 queries, queryA & queryB - these queries are joined on recipeid. example:

queryA

recipeidrecipenamerecipedatequeryb
12345apple pie1/1/2024Table
99999banana pudding2/1/2024Table
654654chocolate cake3/1/2024Table

 

 

queryB

recipeidingredientname
12345apples
12345butter
12345sugar
99999bananas
99999milk
99999nilla wafers
654654chocolate
654654butter
654654even more chololate

 

*I want to keep query a to one row for recipe id, with adding a new column that will return true or false based on the presence of "butter" in the queryb.ingredientname field where the recipeid matches. example output:

 

queryA

recipeidrecipenamerecipedatehasbutter
12345apple pie1/1/2024true
99999banana pudding2/1/2024false
654654chocolate cake3/1/2024true

 

what's the best way to accomplish this please? thanks in advance!

2 ACCEPTED SOLUTIONS
adudani
Super User
Super User

hi @ImaKickUrBut ,

 

output :

adudani_0-1729311648685.png

 

solution is attached. This solution ignores any case sensitivity. Moreover, adding more items in the list where "butter" is hardcoded in the "HasButter" step, would check for any another item added and would mark true.

 

I believe @p45cal , solution will also work. This is an extension with a bit more functinality, in my opinion.

 

If this doesn't resolve the issue, kindly expand on the required output.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

View solution in original post

Bibiano_Geraldo
Super User
Super User

Hi, 

Try to follow these steps:

 

1 - After you merge the tables, instead of expand the merge, choose agregate as shown bellow, and then select the field you want to count, in your case the [recipe id] column:

Bibiano_Geraldo_0-1729346220848.png

 

2. Your result now should look like this:

Bibiano_Geraldo_1-1729346375414.png

 

3. Now add a custom column with this code and click ok: 

if [#"Count of Item No."] > 1 then true else false

Bibiano_Geraldo_2-1729346739612.png

 

 4- Now your table should look like this:

Bibiano_Geraldo_3-1729346866752.png

 

5. now you can remove the count column:

Bibiano_Geraldo_4-1729346941433.png

 

6. Your final result, should look like this:

Bibiano_Geraldo_5-1729347020383.png

 

NOTE: Dont forget to double check the columns names and data type of the columns.

View solution in original post

6 REPLIES 6
Omid_Motamedise
Super User
Super User

To solve this problem in an easiest way, just copy and past the next code into the advance editor ()

let
    QueryA= Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjFV0lFKLCjISVUoyEwFsg31DfWNDIxMgMyQxKScVKVYnWglSxAAiiQl5gGhQkFpSkpmXjpQwAibajNTEyACCiVn5Cfn5ySWpCokJ2aDDDfGUB4LAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [recipeid = _t, recipename = _t, recipedate = _t, queryb = _t]),
    QueryB = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc1JDoAgDAXQqxDWbBwTz2JcVFOHWIEA6vUt0ai0Xb32p20rs7woK6kkWEvoZac+6vcQ0CXk9wluaWLFI9DcPrFtoTUBvRCBOGFEd1/WVcnDm2E2gyEImPLv9Wt4oBabcSg4RE+ouwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [recipeid = _t, ingredientname = _t]),
    #"Merged Queries" = Table.NestedJoin(QueryA, {"recipeid"}, QueryB, {"recipeid"}, "Table1", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each Table.RowCount(Table.SelectRows([Table1],(x)=>x[ingredientname]="butter"))>0)
in
    #"Added Custom"

 

If this answer helped resolve your issue, please consider marking it as the accepted answer. And if you found my response helpful, I'd appreciate it if you could give me kudos. 

Thank you!


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

Hi, 

Try to follow these steps:

 

1 - After you merge the tables, instead of expand the merge, choose agregate as shown bellow, and then select the field you want to count, in your case the [recipe id] column:

Bibiano_Geraldo_0-1729346220848.png

 

2. Your result now should look like this:

Bibiano_Geraldo_1-1729346375414.png

 

3. Now add a custom column with this code and click ok: 

if [#"Count of Item No."] > 1 then true else false

Bibiano_Geraldo_2-1729346739612.png

 

 4- Now your table should look like this:

Bibiano_Geraldo_3-1729346866752.png

 

5. now you can remove the count column:

Bibiano_Geraldo_4-1729346941433.png

 

6. Your final result, should look like this:

Bibiano_Geraldo_5-1729347020383.png

 

NOTE: Dont forget to double check the columns names and data type of the columns.

How this has been accepted as a solution is beyond me!

 

As Marlon Brando might have said in Paris: Où est le beurre?

you were right to call this out. Although @Bibiano_Geraldo's solution was functional, after retrying @adudani 's solution, it was the better one. 

adudani
Super User
Super User

hi @ImaKickUrBut ,

 

output :

adudani_0-1729311648685.png

 

solution is attached. This solution ignores any case sensitivity. Moreover, adding more items in the list where "butter" is hardcoded in the "HasButter" step, would check for any another item added and would mark true.

 

I believe @p45cal , solution will also work. This is an extension with a bit more functinality, in my opinion.

 

If this doesn't resolve the issue, kindly expand on the required output.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash
p45cal
Super User
Super User

= Table.AddColumn(#"Merged Queries", "Butter?", each List.Contains([QueryB][ingredientname],"butter"))

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Kudoed Authors