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
Anonymous
Not applicable

Power Query Custom Column

I'm trying to add a custom column in Power BI Power Query Editor but I'm having some difficulty.
The table below is an example of 2 columns I have and 1 column I require.

I need a Yes to be in the Y/N column whenever an ID does NOT have a DOI assigned. ID can have duplicates, so when any of the same ID's has a DOI then it will be NO, else Yes.

Data Example.png

Thanks

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Please follow the detailed steps:

1.Select the DOI column, right click and select Replace Value, replace - with "".

vkalyjmsft_0-1655284763149.png

vkalyjmsft_1-1655284835134.png

2.Right click the Table and select Duplicate.

vkalyjmsft_2-1655284999515.png

3.In the new table, select ID column then click Group By.

vkalyjmsft_3-1655285114724.png

Set it like below.

vkalyjmsft_4-1655285158165.png

Get the max value for each ID. If all the DOI rows are blank of the same ID, its max value is also blank.

vkalyjmsft_5-1655285232065.png

4.Select the original table then click Merge Queries.

vkalyjmsft_6-1655285423505.png

Set it like this:

vkalyjmsft_7-1655285514199.png

5.Now, in code of the Merged Queries step in the Table, replace the #"Table(2)" with the last step code from the table(2)

vkalyjmsft_8-1655285686441.png

vkalyjmsft_9-1655285765640.png

Get this, then you can delete the Table(2).

vkalyjmsft_10-1655285905066.png

vkalyjmsft_11-1655285926911.png

6.Expand the new column with the Max field.

vkalyjmsft_13-1655286227715.png

7.Add a custom column.

 

if[#"Table (2).Max"]=""then"Yes"else"No"

 

vkalyjmsft_15-1655286443360.png

Then remove the unneeded column, get the expected result.

 

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.

View solution in original post

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

Hi @Anonymous ,

According to your description, here's my solution. Please copy-paste the code in a blank query to see the applied steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVNJRSlSK1YGxdbGwjYhgGxPBNkGyCxfbFEm9KZo4LjZMvRkOtjkRbAsktiWS+ZZo4kB2LAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, DOI = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"DOI", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","-","",Replacer.ReplaceText,{"DOI"}),
    #"Merged Queries" = Table.NestedJoin(#"Replaced Value", {"ID"}, Table.Group(#"Replaced Value", {"ID"}, {{"Max", each List.Max([DOI]), type nullable text}}), {"ID"}, "Max", JoinKind.LeftOuter),
    #"Expanded Max" = Table.ExpandTableColumn(#"Merged Queries", "Max", {"Max"}, {"Max"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Max", "Custom", each if[#"Max"]=""then"Yes"else"No"),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Max"})
in
    #"Removed Columns"

Get the result.

vkalyjmsft_0-1655111715196.png

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.

Anonymous
Not applicable

Hi, thanks for your reply. It does work for the example I provided, but when I try and use the code on the actual data I want to run the query against, It puills through the example data again.

How woudl I get this query to work with other, similar data with the same headings?

Thanks

Hi @Anonymous ,

Please follow the detailed steps:

1.Select the DOI column, right click and select Replace Value, replace - with "".

vkalyjmsft_0-1655284763149.png

vkalyjmsft_1-1655284835134.png

2.Right click the Table and select Duplicate.

vkalyjmsft_2-1655284999515.png

3.In the new table, select ID column then click Group By.

vkalyjmsft_3-1655285114724.png

Set it like below.

vkalyjmsft_4-1655285158165.png

Get the max value for each ID. If all the DOI rows are blank of the same ID, its max value is also blank.

vkalyjmsft_5-1655285232065.png

4.Select the original table then click Merge Queries.

vkalyjmsft_6-1655285423505.png

Set it like this:

vkalyjmsft_7-1655285514199.png

5.Now, in code of the Merged Queries step in the Table, replace the #"Table(2)" with the last step code from the table(2)

vkalyjmsft_8-1655285686441.png

vkalyjmsft_9-1655285765640.png

Get this, then you can delete the Table(2).

vkalyjmsft_10-1655285905066.png

vkalyjmsft_11-1655285926911.png

6.Expand the new column with the Max field.

vkalyjmsft_13-1655286227715.png

7.Add a custom column.

 

if[#"Table (2).Max"]=""then"Yes"else"No"

 

vkalyjmsft_15-1655286443360.png

Then remove the unneeded column, get the expected result.

 

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.

Anonymous
Not applicable

Great work. Thank you very much!

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