cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

Checking if Excel has a table without using FOR EACH loop.

I am trying to check if an excel document has a table, and if it doesn't create one. If it does, don't. The problem I am having is that if I use dynamic content, it goes into for-each loop and the condition will always fail, and is VERY slow.

 

The Excel document I am working with has 1300 rows.... so the loop is painfully slow. So, I am trying to use expressions manually to skip the for-each. Its a singular check, and shouldn't have to go through each row looking for a table.

 

Get tables from excel for business (works) -- > Returns [] when no table or ['Table1'] when there is a generic table

 

Condition:

string(empty(body('Get_tables')?['Value'])) -- > is equal to -- > True | Always returns false.

 

OR

 

empty(body('Get_tables')?['Value']) -- > is equal to -- > True | Always returns false

 

OR

 

body('Get_tables')?['Value'] -- > is equal to -- > empty() or null | Fails, doesn't like the check

 

My question is, how do I use the returned value of [] from Get Tables to trigger a TRUE condition and create a table? Future more, if the excel document has a table and returns ['Table1'], don't. It will return FALSE in the condition, but seeing how when its empty it also returns false, I don't trust that its working correctly.

 

Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @matchrocket ,

 

Have you taken a try with @matchrocket 's solution?, @matchrocket 's solution is works, please take a try with it and your poblem could be solved.

 

length(body('Get_tables')?['value'])

Best regards,

Alice       

 

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

View solution in original post

2 REPLIES 2
Resolver III
Resolver III

Hi @matchrocket,

Try using a condition to check the length of the array returned by "Get tables" as below:

 

I set up what is hopefully a simple version of what you're trying to do, if not let me know if I misunderstood:

GetTables.png

 

The expression I have used in the condition is:

length(body('Get_tables')?['value'])

which checks the length of the array. As we are just checking the array and not the contents of the array there is no need for a loop.

 

Let me know if this helps!

Community Support
Community Support

Hi @matchrocket ,

 

Have you taken a try with @matchrocket 's solution?, @matchrocket 's solution is works, please take a try with it and your poblem could be solved.

 

length(body('Get_tables')?['value'])

Best regards,

Alice       

 

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

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Top Kudoed Authors
Users online (5,935)