Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
micjensen
Frequent Visitor

Custom gruping / Indexing - based on multiple criterias/variables

Hi community

 

I'm trying to make a custom grouping/indexing based on various criterias.

I have a table containing data for people and their helicopter flights/departures. A Scheduled flight can be cancelled and the reservation status will then be "Cancelled" and a new scheduled time will be created for that person --> a new row is then created in the table.

I'm really lost on how to do this, when there is so many different variables that has an impact on the result. All tricks, advices and any sort of help would be highly appreciated, thanks a lot in advance.

I want to group/index the table in the following way:

micjensen_0-1674027952420.png

 

 

 

DaWinci IDNameTransportation dateETDTransportation NoReservation Status
494082JENSEN, Carsten Nybro02.01.202317:30SHW617Cancelled
494082JENSEN, Carsten Nybro05.01.202311:30BBX611Cancelled
494082JENSEN, Carsten Nybro05.01.202311:30BBX611Arrived
494082JENSEN, Carsten Nybro16.01.202308:00BBX605Cancelled
494082JENSEN, Carsten Nybro16.01.202318:00SHW619Cancelled
494082JENSEN, Carsten Nybro17.01.202310:30SHW1619Arrived
498100CHRISTENSEN, Niels Oehlenschläger11.01.202308:00BBX605Cancelled
498100CHRISTENSEN, Niels Oehlenschläger12.01.202307:00SHW1617Cancelled
498100CHRISTENSEN, Niels Oehlenschläger13.01.202311:30BBX611Cancelled
500950GREGERSEN, Dan10.01.202317:30SHW617Cancelled
500950GREGERSEN, Dan10.01.202319:30SHW617Created
500950GREGERSEN, Dan17.01.202323:58SHW617Cancelled
500950GREGERSEN, Dan17.01.202314:30SHW641Cancelled
500950GREGERSEN, Dan18.01.202308:15BBX1641Checked in
489954MARTINSEN, JAN18.01.202308:15BBX1641Arrived


 

 

2 ACCEPTED SOLUTIONS
v-jingzhang
Community Support
Community Support

Hi @micjensen 

 

You can try this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdLdaoMwFAfwVxGvpZyjiSbeWSv9gDnQwgalF86GKhMHsQz2PnuTvdhcdE7HoKbsSk3g5/n4Hw4m4QSYbVrmLorTKLaMMJPNRdRG/PYkX9pzsBeACxtsp/1Az3egfaabBxe99iXM6lxUlTiZR2sORscYdthy+egi/jcWSFm+zqXQHVHAfPimgOrXNcGwx9TE+A2YN8ZgGD922rRLhupf4SbZpvsejEtRNca9KCpRN3lRfbyfhVQD02lZSx4nBryhf/w7Mlq0Mz8/FIDTr/t1Eq2jRLmrrFZjnB/puQr/rUiRXa4b4+3ajk/ZTZVMMkJ+KiFaU2HTQCDtZos9U4j8WZyMsu72xjinpD2/C5L9ttvaLoivO0Nij58=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"DaWinci ID" = _t, Name = _t, #"Transportation date" = _t, ETD = _t, #"Transportation No" = _t, #"Reservation Status" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DaWinci ID", Int64.Type}, {"Name", type text}, {"Transportation date", type date}, {"ETD", type time}, {"Transportation No", type text}, {"Reservation Status", type text}}, "en-GB"),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Flag", each if [Reservation Status] <> "Cancelled" then 1 else 0),
    #"Added Index" = Table.AddIndexColumn(#"Added Conditional Column", "Index", 1, 1, Int64.Type),
    #"Added Conditional Column 2" = Table.AddColumn(#"Added Index", "Row", each if [Flag] = 1 then [Index] else null),
    #"Filled Up" = Table.FillUp(#"Added Conditional Column 2",{"Row"}),
    #"Grouped Rows" = Table.Group(#"Filled Up", {"DaWinci ID", "Name", "Row"}, {{"All Data", each _, type table [DaWinci ID=nullable number, Name=nullable text, Transportation date=nullable date, ETD=nullable time, Transportation No=nullable text, Reservation Status=nullable text, Flag=number, Index=number, Row=number]}}),
    #"Added Index1" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Index1",{"All Data", "Index"}),
    #"Expanded All Data" = Table.ExpandTableColumn(#"Removed Other Columns", "All Data", {"DaWinci ID", "Name", "Transportation date", "ETD", "Transportation No", "Reservation Status"}, {"DaWinci ID", "Name", "Transportation date", "ETD", "Transportation No", "Reservation Status"})
in
    #"Expanded All Data"

vjingzhang_0-1674201556542.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

Thxxx!!!!!! - Great solution, would never figure that out myself.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @micjensen 

 

You can try this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdLdaoMwFAfwVxGvpZyjiSbeWSv9gDnQwgalF86GKhMHsQz2PnuTvdhcdE7HoKbsSk3g5/n4Hw4m4QSYbVrmLorTKLaMMJPNRdRG/PYkX9pzsBeACxtsp/1Az3egfaabBxe99iXM6lxUlTiZR2sORscYdthy+egi/jcWSFm+zqXQHVHAfPimgOrXNcGwx9TE+A2YN8ZgGD922rRLhupf4SbZpvsejEtRNca9KCpRN3lRfbyfhVQD02lZSx4nBryhf/w7Mlq0Mz8/FIDTr/t1Eq2jRLmrrFZjnB/puQr/rUiRXa4b4+3ajk/ZTZVMMkJ+KiFaU2HTQCDtZos9U4j8WZyMsu72xjinpD2/C5L9ttvaLoivO0Nij58=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"DaWinci ID" = _t, Name = _t, #"Transportation date" = _t, ETD = _t, #"Transportation No" = _t, #"Reservation Status" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DaWinci ID", Int64.Type}, {"Name", type text}, {"Transportation date", type date}, {"ETD", type time}, {"Transportation No", type text}, {"Reservation Status", type text}}, "en-GB"),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Flag", each if [Reservation Status] <> "Cancelled" then 1 else 0),
    #"Added Index" = Table.AddIndexColumn(#"Added Conditional Column", "Index", 1, 1, Int64.Type),
    #"Added Conditional Column 2" = Table.AddColumn(#"Added Index", "Row", each if [Flag] = 1 then [Index] else null),
    #"Filled Up" = Table.FillUp(#"Added Conditional Column 2",{"Row"}),
    #"Grouped Rows" = Table.Group(#"Filled Up", {"DaWinci ID", "Name", "Row"}, {{"All Data", each _, type table [DaWinci ID=nullable number, Name=nullable text, Transportation date=nullable date, ETD=nullable time, Transportation No=nullable text, Reservation Status=nullable text, Flag=number, Index=number, Row=number]}}),
    #"Added Index1" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Index1",{"All Data", "Index"}),
    #"Expanded All Data" = Table.ExpandTableColumn(#"Removed Other Columns", "All Data", {"DaWinci ID", "Name", "Transportation date", "ETD", "Transportation No", "Reservation Status"}, {"DaWinci ID", "Name", "Transportation date", "ETD", "Transportation No", "Reservation Status"})
in
    #"Expanded All Data"

vjingzhang_0-1674201556542.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Thxxx!!!!!! - Great solution, would never figure that out myself.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors