Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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?
Solved! Go to Solution.
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"
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
Hi @tomgag01 ,
According to your description, here's my solution.
Select Flag column then click Group By tab under Tansform ribbon.
Set it like this:
Get the result.
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.
Hi @tomgag01,
This may not be the best solution, but it achieved what you required.
Hope this helps.
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"
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 8 | |
| 7 |