Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
I have a table that I need to group by a single field, but I need to return multiple columns with different criteria. My dataset looks like this:
| Job | Operation | Description | Complete |
| ABC | 10 | First Operation | TRUE |
| ABC | 20 | Second Operation | TRUE |
| ABC | 30 | Third Operation | FALSE |
| ABC | 40 | Fourth Operation | FALSE |
| XYZ | 10 | First Operation | FALSE |
| XYZ | 20 | Second Operation | FALSE |
| XYZ | 30 | Third Operation | FALSE |
| XYZ | 40 | Fourth Operation | FALSE |
I need to group by the Job column, and return 6 columns with the following criteria:
This is the desired output:
| Job | First Op | First Op Desc | Last Compl Op | Last Compl Op Desc | Current Op | Current Op Desc |
| ABC | 10 | First Operation | 20 | Second Operation | 30 | Third Operation |
| XYZ | 10 | First Operation | null | null | 10 | First Operation |
In this example, job XYZ has no completed operations so the Last Compl Op and Last Compl Op Desc should return null.
Is it possible to do this in a single group by step?
Solved! Go to Solution.
Hi @ajlindquist,
result:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRMjQAEm6ZRcUlCv4FqUWJJZn5eUCRkKBQV6VYHZgqI5Cq4NTk/LwUfMqMQcpCMjKLUFW5OfoEIyszAduZX1pUkoFDXURkFG63oSvD5Th0dQRdB1FGwHWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Job = _t, Operation = _t, Description = _t, Complete = _t]),
ChangedType = Table.TransformColumnTypes(Source,{{"Operation", type number}, {"Complete", type logical}}),
GroupedRows = Table.Group(ChangedType, {"Job"}, {
{ "First Op", each Table.First(Table.Sort(_, {"Operation", Order.Ascending}))[Operation], type nullable number },
{ "First Op Desc", each Table.First(Table.Sort(_, {"Operation", Order.Ascending}))[Description], type text },
{ "Last Compl Op", each Record.FieldOrDefault(Table.Last(Table.SelectRows(Table.Sort(_, {"Operation", Order.Ascending}), (x)=> x[Complete] = true )), "Operation", null), type nullable number },
{ "Last Compl Op Desc", each Record.FieldOrDefault(Table.Last(Table.SelectRows(Table.Sort(_, {"Operation", Order.Ascending}), (x)=> x[Complete] = false )), "Description", null), type text },
{ "Current Op", each Record.FieldOrDefault(Table.First(Table.SelectRows(Table.Sort(_, {"Operation", Order.Ascending}), (x)=> x[Complete] = false )), "Operation", null), type nullable number },
{ "Current Op Desc", each Record.FieldOrDefault(Table.First(Table.SelectRows(Table.Sort(_, {"Operation", Order.Ascending}), (x)=> x[Complete] = false )), "Description", null), type text }
})
in
GroupedRows
Hi @ajlindquist,
result:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRMjQAEm6ZRcUlCv4FqUWJJZn5eUCRkKBQV6VYHZgqI5Cq4NTk/LwUfMqMQcpCMjKLUFW5OfoEIyszAduZX1pUkoFDXURkFG63oSvD5Th0dQRdB1FGwHWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Job = _t, Operation = _t, Description = _t, Complete = _t]),
ChangedType = Table.TransformColumnTypes(Source,{{"Operation", type number}, {"Complete", type logical}}),
GroupedRows = Table.Group(ChangedType, {"Job"}, {
{ "First Op", each Table.First(Table.Sort(_, {"Operation", Order.Ascending}))[Operation], type nullable number },
{ "First Op Desc", each Table.First(Table.Sort(_, {"Operation", Order.Ascending}))[Description], type text },
{ "Last Compl Op", each Record.FieldOrDefault(Table.Last(Table.SelectRows(Table.Sort(_, {"Operation", Order.Ascending}), (x)=> x[Complete] = true )), "Operation", null), type nullable number },
{ "Last Compl Op Desc", each Record.FieldOrDefault(Table.Last(Table.SelectRows(Table.Sort(_, {"Operation", Order.Ascending}), (x)=> x[Complete] = false )), "Description", null), type text },
{ "Current Op", each Record.FieldOrDefault(Table.First(Table.SelectRows(Table.Sort(_, {"Operation", Order.Ascending}), (x)=> x[Complete] = false )), "Operation", null), type nullable number },
{ "Current Op Desc", each Record.FieldOrDefault(Table.First(Table.SelectRows(Table.Sort(_, {"Operation", Order.Ascending}), (x)=> x[Complete] = false )), "Description", null), type text }
})
in
GroupedRows
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 11 | |
| 9 | |
| 6 | |
| 6 | |
| 6 |