Forum Discussion
Multiple values against a single ID, how to create a column that checks and records.
I feel as though this is definitely answered elsewhere but I cannot find the words to search for it.
Basically I have the table below:
| Doc ID | Comment |
| 111 | Test |
| 112 | Test |
| 111 | Identifier |
| 112 | Test |
| 111 | Test |
| 112 | Test |
And I need to create a column that does this:
| Doc ID | Comment | Comment Check |
| 111 | Test2 | Identifier |
| 112 | Test1 | Fail |
| 111 | Identifier | Identifier |
| 112 | Test2 | Fail |
| 111 | Test1 | Identifier |
| 112 | Test3 | Fail |
If any rows against the Doc ID have the identifier, then a new column would show all rows as having the identifier, if it does not, they all fail or just show their previous value (i.e. Test1, Test2, Test3).
5 Replies
- latimeria
Solution Specialist
Hi CallumJ ,
You can try this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0VNJRCkktLlGK1QFxjVC5IFnPlNS8ksy0zNQi3GqwmhALAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Doc ID" = _t, Comment = _t]), #"Grouped Rows" = Table.Group(Source, {"Doc ID"}, {{"Row", each _, type table [Doc ID=nullable text, Comment=nullable text]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each _[Row][Comment]), #"Expanded Row" = Table.ExpandTableColumn(#"Added Custom", "Row", {"Comment"}, {"Comment"}), #"Added Custom1" = Table.AddColumn(#"Expanded Row", "Check", each if List.Contains([Custom], "Identifier") then "Identifier" else "Fail"), #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Doc ID", "Comment", "Check"}) in #"Removed Other Columns"(copy and paste in a blank query)
- CallumJFrequent Visitor
Hi Latimeria,
I am unable to port the code directly into my Power Query as I have done quite a bit with the data (it is sensitive). I can duplicate the query and do this step by step, are you able to provide the steps to completing this?
- wdx223_Daniel
Community Champion
NewStep=let grp=Table.Buffer(Table.Group(PreviousStepName,"Doc ID",{"n",each if List.Contains([Comment],"Identifier") then "Identifier" else null})) in Table.AddColumn(PreviousStepName,"Comment Check",each grp{[#"Doc ID"=[Doc ID]]}?[n]? ??"Fail")
- CallumJFrequent Visitor
Hi Daniel,
I was unable to port this step into my editor successfully, not sure how to add this as an additional line in my existing code of 10 or so lines.
- CallumJFrequent Visitor
Hi Team,
Unsure if I have given enough information. I have about 15000 lines, in that there are maybe 5500 unique Document ID's. For these they may or may not contain the Identifier in the Comment Column. I already have a large amount of code to get the data to a useable state, so I need something that I can ideally plug in at the end. Worst case scenario I can duplicate the data source and then do a merge on the Document ID.