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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
daez12
Frequent Visitor

Unpivot Date Column - First Post

Hi Power BI Community!

 

This is my first post to this forum, so please let me know if I need to make any adjustments. 

 

Essentially what I'm trying to do is take each unique ATM ID and show status by date over the last 30 days, with each date/status in their own columns. For example:

 

ATM IDDate 30 Days AgoStatus 30 Days AgoDate 29 Days AgoStatus 29 Days AgoDate 28 Days AgoStatus 28 Day Agoetc.etc.etc.
11/21/23Online1/22/23Erroring1/23/23Online   
21/21/23Erroring1/22/23Erroring1/23/23Online   

 

Here is a screenshot of what I've done so far. This Database table is a snapshot by day of status for each ATM. I've filtered the snapshot column to only be within the last 30 days. Thoughts on what I can do here?

Screenshot 2023-02-21 144503.jpg

 

1 ACCEPTED SOLUTION

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

View solution in original post

7 REPLIES 7
daez12
Frequent Visitor

Hi David - I corrected the error and was able to run the step you identified. It did make the ATM Id error out, but I was able to replicate the solution using the matrix visual. I appreciate your willingness to solve this problem with me, and would greatly appreciate your help/advice in the future.

wdx223_Daniel
Super User
Super User

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])

I'm excited to try this! Thank you for your response. How can I go about adding this? Here is my current advanced editor in power query:

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"})
in
#"Removed Columns"

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

Thank you for the follow-up Daniel!

It may be a novice error on my end, but here is the error I'm seeing:

daez12_0-1677165560169.png
It looks like the bracket in New Step is highlighted upon clicking "Show Error." Not sure if this is helpful or not.

 

Thoughts?

 

serpiva64
Solution Sage
Solution Sage

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.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors