What I’d like to do, in PQ, is to be able to produce a column that shows any changes to the previous record. Message ID column would be the identifier and I’d like to return any changes, to the previous record, to the fields Size, Type, Location ID. As records are updated during the day it would need to work out the latest record entry by the Record Updated field which is Date/Time format.
The output column would be blank if no change to previous record but would list the changes as per the second table I’ve included if poss.Changes to previous record PQ.xlsx (12.5 KB)
I hope that you are having a great experience using the Support Forum so far. We’ve recently launched the Enterprise DNA Forum User Experience Survey, please feel free to answer it and give your insights on how we can further improve the Support forum. Thanks!
You don’t have a ChType step but a #“Changed Type” step
Just rename it in the Advanced Editor window so not in the Applied Steps pane and you should be good.
I’ve picked up so many things that are possible from your Power Query videos, just need to go over them a bit more to embed that understanding so I can apply it. Every day is a school day
Just wanted to clarify for my own learning if possible.
The let myIndex = if [ID]-2 >=0 then [ID]-2 else 0 in sets up a way for the new column to iterate through each row as it creates an offset to help with comparing the previous row?
What purpose the ? at the end of this have (if [Size] <> ChType{myIndex}[Size]?
Does it clarify that is it looking at the offset Index we (well you really ) have created?
Changes = Table.AddColumn(ChType, “Changes”, each
let myIndex = if [ID]-2 >=0 then [ID]-2 else 0 in
Text.Combine(
{ (if [Size] <> ChType{myIndex}[Size]? then "Size = " & Text.From( [Size] ) else null),
(if [Type] <> ChType{myIndex}[Type]? then "Type = " & Text.From( [Type] ) else null),
(if [Location ID] <> ChType{myIndex}[Location ID]? then "Type = " & Text.From( [Location ID] ) else null)
}, ", " ), type text
)
this protects the first row from returning an error because it will return a negative value for that row and that is not allowed as (zero based) index value.
the ? (read, question mark) in for example: ChType{myIndex}[Size]? also protects against errors, should the requested position / field not exist than instead of an error a null value is returned
I think I may have neglected to make clear that I need the changes in the data to reflect from the Message ID. It works fine for all the entries except for the highlighted row. Message ID 113 is a unique record but it’s picking up a change type from the previous record Message ID 112. I need any changes to reflect only against the previous instance of the same Message ID, so Message 113 would be blank in this instance.