Forum Discussion
Unpivot Date Column - First Post
- 3 years ago
let
Source = Sql.Database("pmgsql.database.windows.net", "btmdata"),
dbo_MachineStatusSnapshots = Source{[Schema="dbo",Item="MachineStatusSnapshots"]}[Data],
#"Filtered Rows" = Table.SelectRows(dbo_MachineStatusSnapshots, each Date.IsInPreviousNDays([Snapshot], 30)),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"AtmId", "Status", "Snapshot"}),
#"Inserted Date" = Table.AddColumn(#"Removed Other Columns", "Date", each Date.From([Snapshot]), type date),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Date",{"Date"}),NewStep=Table.FromRecords(Table.Group(PreviousStepName,"Atmid",{"n",each let a=Date.From(DateTime.LocalNow()),b=Table.TransformColumns(_,{"Snapshot",Date.From}) in Record.FromTable(Table.FillDown(#table({"Name","Value"],{{"Atmid",a[Atmid]{0}}}& List.TransformMany({0..29},each {"Date","Status"},(x,y)=>{y&" "&Text.From(30-x)&" Days Ago",if y="Date" then Date.AddDays(a,x-30) else b{[Snapshot=Date.AddDays(a,x-30)]}?[Status]?})),{"Value"}))})[n])
in
NewStep
Hi,
it is not clear to me which is your table and which is your desired result
Thank you for your reply! I, unfortunately, haven't found a solution yet.
To clarity, the 1st table in the post is my desired result. The screenshot below it is my current table / Power Query screen.