Forum Discussion
joshua1990
Post Prodigy
4 years agoTRUE FALSE if group contains value
Hi experts! I would like to get a TRUE/FALSE if a group contains a specific value. The structure is like this: Order Nr Value TRUE / FALSE 100 A TRUE 100 B TRUE 102 A FALSE ...
- 4 years ago
Group by Order; then aggregate by the testing if the Value in each group contains "B":
let //change next line to reflect your actual source of data Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order Nr", Int64.Type}, {"Value", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Order Nr"}, { {"Grouped", each _, type table [Value=nullable text]}, {"TRUE/FALSE", each List.Contains([Value],"B"), type logical} }), #"Expanded Grouped" = Table.ExpandTableColumn(#"Grouped Rows", "Grouped", {"Value"}, {"Value"}) in #"Expanded Grouped"
joshua1990
Post Prodigy
4 years agoronrsnfld : Thanks a lot! It works perfectly well. What if the original table has 3 columns? How would you adjust the query to get the 3 columns after expand again?
ronrsnfld
Super User
4 years agoThere are several ways.
You could modify the "Grouped" and "Expanded Grouped" lines:
#"Grouped Rows" = Table.Group(#"Changed Type", {"Order Nr"}, {
{"Grouped", each _, type table [Value=nullable text, 3rd Column=nullable text]},
{"TRUE/FALSE", each List.Contains([Value],"B"), type logical}
}),
#"Expanded Grouped" = Table.ExpandTableColumn(#"Grouped Rows", "Grouped", {"Value","3rd Column"}, {"Value","3rd Column"})