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
tomgag01
New Member

Power Query Task - get the value Y for multiple rows

Hi, something I work on and trying to achive in Power Query.

 

I have the below data with two columns ID and Flag:

ID Flag
1   Y
1   N
1   Y
1   N
1   N
2   N
2
3   Y


and I want to have the below (each Y for ID makes it Y otherwise is N)

ID Flag
1   Y
2   N
3   Y

 

Any ideas how I can do it in Power Query?

1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

Somehow, you are saying that if a number contains all Y, then it should be Y whereas your result are showing Y for 1 which contains multiple Ns as well.

Anyway, I have written the code to match your result i.e. a single Y will make it Y. 

But if you need that it should be N for 1 as well, just change List.AnyTrue to List.AllTrue

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYpUitWBsPzgLGxiEJYRCgvMMIZoiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Flag = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Flag", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Temp", each _, type table [ID=nullable number, Flag=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each let
        DummyTbl = [Temp],
        Result = if List.AnyTrue(List.Transform(DummyTbl[Flag],(x)=>x="Y")) then "Y" else "N"
    in
        Result),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Temp"})
in
    #"Removed Columns"

 

 

View solution in original post

4 REPLIES 4
v-yanjiang-msft
Community Support
Community Support

Hi @tomgag01 ,

Is your problem solved?? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.

Best Regards,
Community Support Team _ kalyj

v-yanjiang-msft
Community Support
Community Support

Hi @tomgag01 ,

According to your description, here's my solution.

Select Flag column then click Group By tab under Tansform ribbon.

vkalyjmsft_0-1652687290851.png

Set it like this:

vkalyjmsft_1-1652687363208.png

Get the result.

vkalyjmsft_2-1652687391343.png

Here's the applied code.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYpUitWBsPzgLGxiEJYRCgvMMIZoiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Flag = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Flag", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Flag", each List.Max([Flag]), type nullable text}})
in
    #"Grouped Rows"

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

mussaenda
Super User
Super User

Hi @tomgag01,

 

This may not be the best solution, but it achieved what you required.

mussaenda_0-1652191103546.png

 

Hope this helps.

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

Somehow, you are saying that if a number contains all Y, then it should be Y whereas your result are showing Y for 1 which contains multiple Ns as well.

Anyway, I have written the code to match your result i.e. a single Y will make it Y. 

But if you need that it should be N for 1 as well, just change List.AnyTrue to List.AllTrue

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYpUitWBsPzgLGxiEJYRCgvMMIZoiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Flag = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Flag", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Temp", each _, type table [ID=nullable number, Flag=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each let
        DummyTbl = [Temp],
        Result = if List.AnyTrue(List.Transform(DummyTbl[Flag],(x)=>x="Y")) then "Y" else "N"
    in
        Result),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Temp"})
in
    #"Removed Columns"

 

 

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.

Top Solution Authors