none
Why is Table.IsEmpty slow? RRS feed

  • Question

  • Hi,

    I need to join two tables. After join, I will do some following steps. At the beginning, I thought, I can use Table.IsEmpty to check the two tables, if one of them is empty, I do not need to join, and the following steps can be saved. So I use 

     Merge= if Table.IsEmpty(Table1) then Table.FirstN(TableSample,0) else Table.Join(Table1,aa,Table2,aa,JoinKind.Inner),

    However, it takes forever to refresh the query.

    When I change it to 

    Merge=  Table.Join(Table1,aa,Table2,aa,JoinKind.Inner),

    It takes only a few seconds.

    Can anyone explain why Table.IsEmpty makes it so slow.

    Thanks

    Tuesday, November 17, 2015 5:32 PM

Answers

  • Use RowCount instead, probably should be lots faster.

    https://msdn.microsoft.com/en-us/library/mt260841.aspx

    This is not unique problem with Power Query, it happens in other languages as well:

    https://github.com/rethinkdb/rethinkdb/issues/4592

    • Marked as answer by bjzk Tuesday, November 17, 2015 6:40 PM
    Tuesday, November 17, 2015 6:33 PM

All replies

  • Use RowCount instead, probably should be lots faster.

    https://msdn.microsoft.com/en-us/library/mt260841.aspx

    This is not unique problem with Power Query, it happens in other languages as well:

    https://github.com/rethinkdb/rethinkdb/issues/4592

    • Marked as answer by bjzk Tuesday, November 17, 2015 6:40 PM
    Tuesday, November 17, 2015 6:33 PM
  • Greg is right that it might be slow depending on the data source or query you're running it against. That being said, the current implementation of the function is perhaps not optimal for cases where it can be optimized to the data source. You can try doing Table.RowCount(Table.FirstN(table, 1)) = 0 instead.
    Tuesday, November 17, 2015 7:32 PM
    Moderator