cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jdusek92
Helper III
Helper III

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:

 

 

expand2.gif

 

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:

 

expand3.gif

 

 

 

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

 

 

1 ACCEPTED SOLUTION

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!

 

View solution in original post

13 REPLIES 13
Anonymous
Not applicable

I found that inseting a index colum before the exanding step seems to fix the issue.

v-lili6-msft
Community Support
Community 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

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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:

 

expand4.gif

 

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

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

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello,

for anyone wondering - it is a bug and I have provided MS developers with a sample file:

https://drive.google.com/file/d/1SC0o3eO_HftVtJ-imU0bUc6XHj_b0dsW/view?usp=sharing

 

expand5.gif

 

 

After few hours I was able to prepare a sample excel file that carries the source data, queries and also the BUG.

 

query “FINAL” contains the BUG in the last step.

 

I have also discovered a new fact:

  • Expand Column step does not only remove some rows. But also the resulting rows are completely different – it returns back rows that have been removed in previous steps. (see the attached gif)
  • As I was able to place everything in Excel file that means that it has nothing to do with the Access connector
  • My guess is that the combination of sorted rows and remove duplicates is to blame
  • If I add Table.Buffer in the Expand Column it works fine
    • = Table.ExpandTableColumn(#"Merged Queries", "Query1", {"Column1"}, {"Query1.Column1"})
    • = Table.ExpandTableColumn(Table.Buffer(#"Merged Queries"), "Query1", {"Column1"}, {"Query1.Column1"})
  • If I add a custom column BEFORE Expand Query:
    • = Table.AddColumn(#"Merged Queries", "Custom", each Table.RowCount([Query1]))  - DOES HELP
    • = Table.AddColumn(#"Merged Queries", "Custom", each "SSSS") DOES NOT HELP

 

Looking at the things that help, it seems to me that the query needs to be “kicked” to “recalculate” with functions like Table.Buffer or Table.RowCount that forces the query to do it.

 

 

I found out the same issue by mere coincidence (I was missing some data and went looking where it went). Two years have passed and the bug is still here.

Thanks for this, unfortunately the Table.Buffer techinque was making my query run incredibly slowly and adding the row count column didn't seem to do anything.

 

I also tried changing the merge type to a Full Outer (full rows from both tables) then filtering out the rows added from doing the Right Outer part of the merge. Came back with the same number of rows 😞

 

This is in Excel Power Query (on Office 365) rather than in Power BI but the principles should be the same.

Anonymous
Not applicable

Did you ever found a solution?

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!

 

View solution in original post

Anonymous
Not applicable

Thank you for your response.

 

As far as I understood the article you sent me, merging a table deletes or ignores the sort order. However I find that in my data set, the row numbers don't match (before and after the operation). Was this the case in you scenario ?

 

Andrei

Yes, that could be similar to my scenario.

Try putting Table.Buffer to the Merge Step - not around the whole step, but around the merging tables

 

hi, @jdusek92 

Thank you for your feedback, I have reported this to power bi product team, if there is any update, I will post here.

 

Best Regards,
Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi to everyone!

 

Im just reporting that the issue still exist. Thanks to @jdusek92 for the table.buffer solution it helped me a lot.

 

Best Regards,

 

Campagna Cristian

Operational Data analyst on Aerolineas Argentinas

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors
Top Kudoed Authors