Forum Discussion
mmunozjr5
2 years agoFrequent Visitor
Return Values Only if a Unique Condition Occurs
I have a table that contains these 3 columns. I am trying to create a reference table in Power Query based on this table that would only bring in the Call IDs, only if the same call ID number has ALL...
- 2 years ago
Hi mmunozjr5
Download PBIX file with example below
Not sure what you mean by a reference table - please supply an example of the exact result you want. Do you simply want a column with 2 numbers in it (in this case)?
If so you can do it like this
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MjC1UNJR8tJTCM7NLMkAMv3ylWJ1kKQc9RSc83NyMvOKsUgG6yn45ReV5OchyZlYWBgbAPlOIDMTi0qAzMjUYoicqZmBsQlEn09+XiaykTApb6B9pUUlYDm4Pgtzc0MjoEA4pjthUm56CkH5SalFJcVYJIH+c07MS87MR3GMpaWxIcRGl8S84tQcZNdA5QL0FCJLYb6LBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Call ID" = _t, Recipient = _t, Responded = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Call ID", Int64.Type}, {"Recipient", type text}, {"Responded", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Call ID"}, {{"Count", each _, type table [Call ID=nullable number, Recipient=nullable text, Responded=nullable text]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each if List.Contains([Count][Responded], "Yes") then 0 else 1), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Count", "Custom"}) in #"Removed Columns"- Group by the Call ID, keep all rows
- Create a column by checking the Responded column in the resultant table for any occurrence of "yes". Mark "yes" as 0 else 1
- Remove any rows with 0
Regards
Phil
- 2 years ago
DAX is not only more concise, but more efficient as well. Try with a dataset of more than 10k+ rows to feel the advantage.