Forum Discussion
joshua1990
Post Prodigy
3 years agoGroup Table with multiple conditions
Hi all!
I have a table structured in this way:
Sales Nr
Sales Type
Status
1
ABC-1
A
1
ABC-1
C
1
XYZ-1
A
2
ABC-5
A
3
ABC-9
A
3
A...
- 3 years ago
Hi joshua1990 ,
I would do it like so:let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJ0ctYF00qxOqgiznCRiMgoJDVGUDWmcBFjqIglVhEnsIgJ1BwziJpYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sales Nr" = _t, #"Sales Type" = _t, Status = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales Nr", Int64.Type}, {"Sales Type", type text}, {"Status", type text}}), #"Grouped Rows" = Table.Group( #"Changed Type", {"Sales Nr", "Sales Type"}, {{"IsActive", each not List.Contains([Status], "B"), type nullable text}} ), #"Inserted Text Before Delimiter" = Table.AddColumn( #"Grouped Rows", "SalesType", each Text.BeforeDelimiter([Sales Type], "-"), type text ), #"Added Custom" = Table.AddColumn( #"Inserted Text Before Delimiter", "Custom", each [ IsABC = [SalesType] = "ABC", IsXYZ = [SalesType] = "XYZ", IsActiveXYZ = IsXYZ and [IsActive], IsActiveABC = IsABC and [IsActive] ] ), #"Removed Columns" = Table.RemoveColumns(#"Added Custom", {"IsActive", "SalesType"}), #"Expanded Custom" = Table.ExpandRecordColumn( #"Removed Columns", "Custom", {"IsABC", "IsXYZ", "IsActiveXYZ", "IsActiveABC"} ) in #"Expanded Custom"
Please also check enclosed file.
ImkeF
Community Champion
3 years agoHi joshua1990 ,
I would do it like so:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJ0ctYF00qxOqgiznCRiMgoJDVGUDWmcBFjqIglVhEnsIgJ1BwziJpYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sales Nr" = _t, #"Sales Type" = _t, Status = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales Nr", Int64.Type}, {"Sales Type", type text}, {"Status", type text}}),
#"Grouped Rows" = Table.Group(
#"Changed Type",
{"Sales Nr", "Sales Type"},
{{"IsActive", each not List.Contains([Status], "B"), type nullable text}}
),
#"Inserted Text Before Delimiter" = Table.AddColumn(
#"Grouped Rows",
"SalesType",
each Text.BeforeDelimiter([Sales Type], "-"),
type text
),
#"Added Custom" = Table.AddColumn(
#"Inserted Text Before Delimiter",
"Custom",
each [
IsABC = [SalesType] = "ABC",
IsXYZ = [SalesType] = "XYZ",
IsActiveXYZ = IsXYZ and [IsActive],
IsActiveABC = IsABC and [IsActive]
]
),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom", {"IsActive", "SalesType"}),
#"Expanded Custom" = Table.ExpandRecordColumn(
#"Removed Columns",
"Custom",
{"IsABC", "IsXYZ", "IsActiveXYZ", "IsActiveABC"}
)
in
#"Expanded Custom"
Please also check enclosed file.