Forum Discussion
cathoms
Responsive Resident
1 year agoAdd index or rank number based on groups in Power Query
Hi! I'm helping someone with a Power BI report. We need to report the next 12 available appointment slots by slot length. Most slots are 15 minutes, but the end-user wants to group adjacent open 15 m...
- 1 year ago
Hi cathoms
You will need to use the Group By multiple times and create an index column within one of the tables created by grouping.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRT0lEyMNE3NNQ3MjAyVTA0sTIwAAoZmir4ZuaVlqQWK8XqRCsZG6EpM7YyMcVUZm5OkTJjA6KUmRAwDbsXyFdmiMVthmZoAWeJ1TRcyog0zYSgaYZYgheLMmNi3GZoiumHWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PROV_ID = _t, SLOT_BEGIN_TIME = _t, SLOT_LENGTH_MINUTES = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"PROV_ID", Int64.Type}, {"SLOT_BEGIN_TIME", type datetime}, {"SLOT_LENGTH_MINUTES", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"PROV_ID", "SLOT_BEGIN_TIME"}, {{"Group", each _, type table [PROV_ID=nullable number, SLOT_BEGIN_TIME=nullable datetime, SLOT_LENGTH_MINUTES=nullable text]}}), #"Grouped Rows1" = Table.Group(#"Grouped Rows", {"PROV_ID"}, {{"Group", each _, type table [PROV_ID=nullable number, SLOT_BEGIN_TIME=nullable datetime, Group=table]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows1", "Group With Index", each Table.AddIndexColumn([Group], "Index", 1, 1)), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Group"}), #"Expanded Group With Index" = Table.ExpandTableColumn(#"Removed Columns", "Group With Index", {"SLOT_BEGIN_TIME", "Group", "Index"}, {"SLOT_BEGIN_TIME", "Group", "Index"}), #"Expanded Group" = Table.ExpandTableColumn(#"Expanded Group With Index", "Group", {"SLOT_LENGTH_MINUTES"}, {"SLOT_LENGTH_MINUTES"}), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Group",{{"SLOT_BEGIN_TIME", type datetime}, {"SLOT_LENGTH_MINUTES", type text}, {"Index", Int64.Type}}) in #"Changed Type1"
lbendlin
Super User
1 year agoPlease provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523