Share via

How can I set Power Automate to count amount of rows by category in one column?

Prchalová Tereza 60 Reputation points
2025-08-05T10:28:47.43+00:00

How can I set up Power Automate to count rows based on a condition? Kind of like XLOOPUP in Excel.

Microsoft 365 and Office | Excel | Other | Windows
0 comments No comments

Answer accepted by question author

Chen1018 13,870 Reputation points Independent Advisor
2025-08-05T11:04:45.8233333+00:00

Hi there,

I’m Cherrelyn, and I’m here to help.

Please try these suggestion:

  1. Use “Get rows” (for Excel, SharePoint, etc.) to pull in your data.
  2. Add an “Initialize variable” action:
    • Name: CategoryCount
    • Type: Object
    • Value: {}
  3. Use an “Apply to each” loop to go through each row.
  4. Inside the loop, add a “Set variable” action:
    • Use expression logic like:
    if(contains(variables('CategoryCount'), item()?['CategoryColumn']), set(variables('CategoryCount')['CategoryColumn'], add(variables('CategoryCount')['CategoryColumn'], 1)), set(variables('CategoryCount')['CategoryColumn'], 1) )
  5. After the loop, your CategoryCount variable will hold the count per category.

This mimics Excel’s counting grouped by a specific column.

I hope this helps, and if you have any questions, feel free to reply to this post.

Warm regards,

Cherrelyn

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Chen1018 13,870 Reputation points Independent Advisor
    2025-08-05T12:44:35.0133333+00:00

    Hi Tereza,

    Thank you for your kind message and I’m really glad to hear you’re making progress!

    The error you're seeing happens because Power Automate doesn’t allow updating a variable using its own value directly (self-reference).

    Instead of updating the object in place, use union() to merge the updated value:

    union(variables('CategoryCount'), json(concat('{ "', item()?['Category'], '": ', add(coalesce(variables('CategoryCount')[item()?['Category']], 0), 1), ' }')))

    This creates a new object each time without self-referencing.

    Once your counting works, you can connect it to SharePoint using Get items, then use Update item to sync the counts by category.

    Warm regards,

    Cherrelyn

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.