Forum Discussion
Creating column to show previous row
Hi All,
I want to create a column that will provide me with the previous row. For example the second cell in the column would be the date 6/2/2019 5:39:58PM and so on.
Thank you
7 Replies
- zoloturuMemorable Member
Hi Anonymous ,
To do that you need to modify PowerQuery code under your query.
Step1. Add an index column (which starts from zero).
Step2. Add a custom column with next code (just copy and paste it)
let CurrentIndex = [Index], PreviousIndex = CurrentIndex - 1, PreviousValue = try #"Added Index"[Date]{PreviousIndex} otherwise null in PreviousValue(Where 'Added Index' the name of a last step for the moment in your query. If you have English Power BI Desktop then it will be the same, no need to change. And [Date] - your date column. Other code are variables.
Look
Result will be like next:
Regards,
Ruslan Zolotukhin (zoloturu)
BI Engineer at Akvelon Inc. / Kharkiv Power BI User Group Leader / DAX & Power BI Trainer
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!
It was useful? Press Thumbs Up!
You are from Ukraine? If yes then welcome to Power BI User Group - KhPUG website. Other country? Check and find proper one - Power BI User Groups- AnonymousNot applicable
I am getting "null" in each column after pasting that as a query in query editor
- AnonymousNot applicable
Not sure if the other columns I have on the same table are interferring with the query?