Showing results for 
Search instead for 
Did you mean: 
New Member

Row Index being Reordered After Merge.

Hi Community


 Just playing around with PowerBI, but I ran into something that I confused about.


Basically I am trying to shape the data so that for a given row i the previous two rows ( and their respective row values, I've only show year for example) will appear in the row as two new columns kind of like the lag window function used in SQL. I decided to use a merge method where I merge the table with itself using the indexing as the join paremeter. My Row Indexes are t (current row), t-1 (1 previous row) and t-2 (previous two rows). Represented below: 




I've only provided a small snippet basically there is a row index for every group

Group  Row t   Row t-1 Row t-2

A               0            -1         -2        

B               1             0          -1

C               2             1           0


This works for some group but noticed it doesn't work for some others after I expand. 
In one of the scenarios after merging I look at the output before expanding it shows what should happen, in this case for year 2015 the picture displays the possible new columns appended after merging.


But when I expand  - the indexes change and the ordering becomes messed if I want to append row t-2.



I think i would just have to reset the indexes when i do another merge (would like to avoid that) but I just want to know why would this occur.



Helper I
Helper I

I have the same problem.. 


Hi @sunc,


Could post some sample data and all the power query(M formula) you're applying to reproduce this issue, so that we can further investigate on this issue? It's better to share a sample pbix file. You can upload it to OneDrive or Dropbox and post the link here. Do mask sensitive data before uploading. Smiley Happy



any solution?

Helpful resources

PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

April Update

Check it Out!

Click here to read more about the April 2021 Updates!

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!


The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.