Forum Discussion
Transform data in grouped periods
- 2 years ago
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdY9a8MwEAbgv2I8x2B9S2vbqVOgkAwhg0tFCRgT7P5/eunQYl2Hs14PBiP8vDrsQ77LpX0a5q/mmO95XNpDez41pzy/36aP2/SZJ1pp6NKx853utaX7t/PLY8W314MQJwCbHsCqC4UN8qoBawBroZrj2hq1oeZ6awHrmNVi6wEbABuhmlNh5f0cABsBm5iV96TqEawQrLGdqfKVtvKmpq0RbSBtuZa3p3KQ9pAOaOWq0Bt+FR7SAdKR6w2dmhCte0grSNNb02vt5N+bZhJEJ0TTVMK0kWuFaMIP636t/GjQ/9PnnJfmdZiWnwcL2hyHeRjHPP4dL+VAZitS3C4pfpeUwFJcRQofkWtS+KxckaL50FxXSzmKpqpa9kjhozylXL8B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Naam = _t, Groep = _t, Aanwijzing = _t, Datum = _t, Waarde = _t, SumWeeknummer = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Datum", type date}},"nl"), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type), #"Grouped Rows" = Table.Group(#"Added Index", {"Naam", "Groep", "Aanwijzing", "Waarde", "Datum", "Index"}, {{"Rows", each _, type table [Naam=nullable text, Groep=nullable text, Aanwijzing=nullable text, Datum=nullable date, Waarde=nullable text, SumWeeknummer=nullable text, Index=number]}},GroupKind.Local,(x,y)=>Number.From(try y[Datum]<>Date.AddDays(#"Added Index"{y[Index]-1}[Datum],1) otherwise true)) in #"Grouped Rows"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
Obligatory reference: ImkeF https://www.thebiccountant.com/2018/01/21/table-group-exploring-the-5th-element-in-power-bi-and-power-query
- Anonymous2 years ago
Hi DekkerNick
Here is my method for your reference.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdY9a8MwEAbgv2I8x2B9S2vbqVOgkAwhg0tFCRgT7P5/eunQYl2Hs14PBiP8vDrsQ77LpX0a5q/mmO95XNpDez41pzy/36aP2/SZJ1pp6NKx853utaX7t/PLY8W314MQJwCbHsCqC4UN8qoBawBroZrj2hq1oeZ6awHrmNVi6wEbABuhmlNh5f0cABsBm5iV96TqEawQrLGdqfKVtvKmpq0RbSBtuZa3p3KQ9pAOaOWq0Bt+FR7SAdKR6w2dmhCte0grSNNb02vt5N+bZhJEJ0TTVMK0kWuFaMIP636t/GjQ/9PnnJfmdZiWnwcL2hyHeRjHPP4dL+VAZitS3C4pfpeUwFJcRQofkWtS+KxckaL50FxXSzmKpqpa9kjhozylXL8B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Naam = _t, Groep = _t, Aanwijzing = _t, Datum = _t, Waarde = _t, SumWeeknummer = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Naam", type text}, {"Groep", type text}, {"Aanwijzing", type text}, {"Datum", type date}, {"Waarde", type text}, {"SumWeeknummer", Int64.Type}}, "en-GB"), #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Naam", Order.Ascending}, {"Groep", Order.Ascending}, {"Datum", Order.Ascending}}), #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type), #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 0, 1, Int64.Type), #"Merged Queries" = Table.NestedJoin(#"Added Index1", {"Naam", "Groep", "Aanwijzing", "Waarde", "Index"}, #"Added Index1", {"Naam", "Groep", "Aanwijzing", "Waarde", "Index.1"}, "Added Index1", JoinKind.LeftOuter), #"Expanded Added Index1" = Table.ExpandTableColumn(#"Merged Queries", "Added Index1", {"Datum"}, {"Datum.1"}), #"Added Custom" = Table.AddColumn(#"Expanded Added Index1", "Custom", each if [Datum.1] = Date.AddDays([Datum],1) then 1 else 0), #"Added Custom1" = Table.AddColumn(#"Added Custom", "End Date", each if [Custom] = 0 then [Datum] else null), #"Filled Up" = Table.FillUp(#"Added Custom1",{"End Date"}), #"Changed Type1" = Table.TransformColumnTypes(#"Filled Up",{{"End Date", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type1", {"Naam", "Groep", "Waarde", "Aanwijzing", "End Date"}, {{"Start Date", each List.Min([Datum]), type nullable date}}) in #"Grouped Rows"Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information or anything not related to the issue or question.
If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523