Forum Discussion
Dont display table if empty
Hi,
I have two tables (A and B) that merge as a single table(C),
If table B is empty i dont want the table(C) to be displayed on the sheet.
I have tried ISempty function for some reason i feel like im not doing it right.
Any help would be appreciated!
7 Replies
- jbwtpMemorable Member
Hi jijoythomas29,
I don't think PQ can "delete" table from Excel if it is empty. On the Excel side, it is a "connection" (like a data pipe from PQ), PQ does not have control over it. Excel does not like if you don't return a table, the query in this case would exit with an error. The closest that I think you can potentially get to what you need is to load a one column, empty table like this:
let A = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyaKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), B = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyaKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]), #"Filtered Rows" = Table.SelectRows(B, each [Column1] = "A"), #"Merged Queries" = Table.NestedJoin(#"Filtered Rows", {"Column1"}, #"Filtered Rows", {"Column1"}, "B", JoinKind.LeftOuter), C = if Table.IsEmpty(#"Filtered Rows") then #table({"Empty"},{}) else Table.ExpandTableColumn(#"Merged Queries", "B", {"Column1"}, {"B.Column1"}) in CCheers,
John
- jijoythomas29New Member
Thank you!
Let me test this out!
- miguelCommunity Admin
If this for Power Query in Excel, perhaps you could create your own VBA code that first runs a query to test if Table B is empty and if its not then it then evaluates the full query. Otherwise the VBA code will clean the sheet.
It's mainly about leveraging VBA for your solution.
- jijoythomas29New Member
is there a way to clear the table if there is no more than 2 rows in the table using VBA?
I know how to clear the worksheet but not sure how to clear the specific table based on the condition.
- miguelCommunity Admin
There's probably a way to check if the table X amount of rows and then you can delete the table in VBA.
I'd recommend posting questions around VBA for Excel on the forum below:
office-vba-dev - Microsoft Q&A
These sorts of automations are primarily driven outside of Power Query and only enabled or limtied by the product integration which in this case is Excel, so it is recommended that you post this question in a forum more focused towards Excel like the one I provided above.
Best!