Forum Discussion
Dynamic number of calculated columns (Project Online schedule dates)
- 1 year ago
iainh Here is a more refined approach in case there are duplicate publish dates, refer to Solution2
let Source = Data, Unpivot = Table.UnpivotOtherColumns ( Source, { "Project #" }, "Publish#", "Published On" ), RemoveBlanks = Table.SelectRows ( Unpivot, each [Published On] <> " " and [Published On] <> null ), ChangedType = Table.TransformColumnTypes ( RemoveBlanks, { { "Published On", type date }, { "Project #", Int64.Type } }, "en-GB" ), GroupedRows = Table.Group ( ChangedType, { "Project #" }, { { "Transform", each let a = _, b = a[Published On], c = List.Accumulate ( b, [ Dates = { List.First ( b ) }, vsPrevious = { 0 }, vsNext = { 0 } ], ( s, c ) => [ Dates = s[Dates] & { c }, vsPrevious = s[vsPrevious] & { Duration.Days ( c - List.Last ( s[Dates] ) ) }, vsNext = s[vsNext] & { Number.Abs ( Duration.Days ( List.Last ( s[Dates] ) - c ) ) } ] ), d = Record.TransformFields ( c, { { "vsPrevious", List.Skip }, { "vsNext", each List.Skip ( _ , 2) & {0} } } ), e = { { "n - 1" } & d[vsPrevious] } & { { "n + 1" } & d[vsNext] }, f = Table.ToColumns ( Table.DemoteHeaders ( a ) ), g = Table.PromoteHeaders ( Table.FromColumns ( f & e ) ) in g } } ), CombineTables = Table.Combine ( GroupedRows[Transform], type table [ #"Project #" = Int64.Type, #"Publish#" = text, Published On = date, #"n - 1" = Int64.Type, #"n + 1" = Int64.Type ] ) in CombineTablesFile attached below
One of the very first methods to learn when coming from Excel to Power BI is to unpivot your data to bring it into a usable format. In your case you will want to end up with a table with three columns
- project
- version
- date
Let the visuals do the re-pivoting for you.
Hello, thanks for your reply.
Apolgises I don't think I explained myself clearly or I've misunderstood. In essence I want to end up with a table that includes the slippage duration for the respective publish versions. The published versions are ranked incermentally (from 1). This way I can track the slipage movement of the respective date/s in a table. This will then be used in by other dataflows for other purposes i.e., tracking schedule accuracy performance, ifdentifying top movers for business areas etc
Thanks
Iain