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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors