Forum Discussion
Power Query - Row disappear after expand column
Hello,
I have encountered a strange thing when I expand merged table column.
I use JoinKind.LeftOuter to merge queries - that should keep all the rows from the first/left table - and it does.
But when I expand the column I loose 2 out of 719 rows. How is that possible?
Here is a gif with only 2 filtered rows, but it shows the behavior:
the table contains personal details so I cannot share it or show more columns but it is always the SAME PERSON that disappears after expanding.
EDIT:
I wanted to add a custom column showing the row count of the expading table, but after this step, the row DOES NOT dissapear:
Any explanation please? I really dont understand that and it really scares me that I might be loosing rows in my other queries!
(the same thing happens in Power Query Excel)
Warm regards
Jakub
Hello,
I have been told that this this "this behavior is intentional. Operations like “distinct” and “merge” do not guarantee that an input sort order is preserved. This is because in cases when we run the operation against a relational database, the database itself does not preserve the sort order."
Here is some help text about it: https://docs.microsoft.com/en-us/power-query/commonissues#preserving-sort
Personally I don't quite understand nor argee how this is an intentional behavior, when a preview in one step is showing different values then in the next step.
Seeing steps in the right pane is giving anybody a false understanding of how power query process data: Not in sequentional steps as seen in the steps pane, but in a different hidden way that cannot be predicted.This feature has already caused me a lot of trouble. So be aware!
19 Replies
- AnonymousNot applicable
I found that inseting a index colum before the exanding step seems to fix the issue.
- liz72Advocate I
Legend. Thank you! This was making me crazy!
- MelodyvHelper I
I realize this was posted 4 years ago, but I just had to say this was a great solution! This problem was driving me crazy and I could not for the life of me figure it out. Thank you!
- bradwest414Frequent Visitor
I had a report that was working for 2 years and suddenly rows started disappearing. Inserting an index column after the merge, before the expand, worked beautifully. THANK YOU
- AnonymousNot applicable
Hello! I might be late a bit to the party, but I ran in the same situation. My database is kind of large and complex.
- In my case, using Table.Buffer with the expand step didn`t work, since it slowed it down. My PC froze as well.
- Adding an index column before the expand step worked, but again it was slowing down my querry a lot.
What worked for me:
- I always sort used in the merge process in same direction (ascending/A-Z etc)
- This round, I added in a Table.Buffer in fron of the Table.Sort, and the merge was successful.
Sort step = Table.Buffer(Table.Sort(#"Renamed Columns",{{"FP&A Department", Order.Ascending}}))
Merge step: = Table.NestedJoin(#"Sorted Rows", {"FP&A Department"}, #"FP&A Key", {"FP&A Department"}, "FP&A Key", JoinKind.LeftOuter)
Expand Step = = Table.ExpandTableColumn(#"Merged Queries", "FP&A Key", {"Allocation Key"}, {"Allocation Key"})
For me, it helped with:
- Preventing the merge process to create "null" entries on the existing rows
- It was finally pulling all rows from FP&A Key table (FP&A Key table had 3 rows matching to my main table, but due to the issue it was not pulling all of them)
Just sharing this solution which worked for me in case it can help someone else, while all the other options are working as you`d like to.
- FrisoWHelper I
Another 2 years later. For me Table.Buffer messed the merging step up, before even expanding.
I managed to solve it by doing the merge query and expansion at the beginning of all the steps.
Doesn't make sense at all, cost me hours of frustration.How can I ever trust my data again...
- jdusek92Advocate III
Hello,
since I encountered this problem and its cause, I am always cautious when using Distinct+Sorting+Merging in a query
- v-lili6-msftCommunity Support
hi, jdusek92
I have tested on my side, but not reproduce the issue.
I think there should be something wrong with your JoinKind.LeftOuter to merge queries,
Could you please check if the matching column from two tables could be mached.
If not your case, please use virtual data or some sample data to create a simple sample pbix file for us have a test.
Best Regards,
Lin
- jdusek92Advocate III
Hello,
unfortunately I cannot share sample data - the source data is pulled from ACCESS db.
when I try to store sample data in Excel table, the problem does not occur.
Clearing cache did not help
Anyways I tried to use Table.Buffer in Expand step:
Please see the gif below that show different results with/without Table.Buffer:
Could anyone please explain different results?
Does it mean that the basic merge/join feature is that unreliable and I have to go through all my queries (dozens) and check for lost rows?
Warm regards
Jakub
- v-lili6-msftCommunity Support
hi, jdusek92
From the screenshot, there is no match value in"KATALOG" table, so that leads to this issue.
eg. there is no "999" in idPos column of "KATALOG" table. Therefore it returns null value.
https://docs.microsoft.com/en-us/powerquery-m/table-join
https://docs.microsoft.com/en-us/powerquery-m/joinkind-leftouter
Best Regards,
Lin