Forum Discussion

sunc's avatar
sunc
New Member
9 years ago

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.

 

Thanks!

4 Replies

  • v-ljerr-msft's avatar
    v-ljerr-msft
    Microsoft Employee

    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. :smileyhappy:

     

    Regards

  • Anonymous's avatar
    Anonymous
    Not applicable

    I have the same problem.. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    I noticed this issue too. Trying to build an index so that I can reference the same postion without it changing. But after a merge, it canges.