Forum Discussion
Creating a powerquery to fix a table
- May 27, 2020
Not sure there is the source data - in another file or in Table/range of the current file. In general that's doesn't matter, just to build the sample
Let select columns from A to E and name selection as Range. Query it.
Add index column to the table.
Sort on first column to combine same ID:s together, right after that sort on Index in descending order to keep the latest records first.
Add one more index column to fix result in memory (or wrap previous step with Table.Buffer() ).
Select first column, Remove duplicates.
Remove bot columns with indexes.
Load result back into the sheet.
More exactly, not the second but the latest appeared in the list. Second index is only to fix in memory in UI without adding Table.Buffer manually.
SergeiBaklan True! Should have written "latest record". But in this example the second record = the latest record, as there were only two occasions of R033. I would have written "the third record" if there had been three.
Will have to look into Table.Buffer as I haven't come across that one yet in my discoveries of PQ.
- Ocasio27May 28, 2020Iron Contributor
There is a possibility of a third, even forth record (they really want to make things hard for me).
Will the code work anyway?
- Riny_van_EekelenMay 28, 2020Platinum Contributor
Ocasio27 Tested it with your example data. It doesn't matter how many records you have per item. However, once a field has received a value other than (blank), the current query does not allow it to be reset to (blank), as it is interpreted as "no change" compared with the previous record. Perhaps possible, but then you'll have to tweak the query. And of course, you'll still have to adapt the query to your real data range, possibly with headers.