web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Counting occurrence of...
Power Automate
Unanswered

Counting occurrence of a value in Power Automate Flow

(0) ShareShare
ReportReport
Posted on by 206

In a flow, after my get items step, I am looking to count the total times a SharePoint list value occurs:

SPList Name = VehicleInventory

SPColumn Name = VehicleModel

Column Values (as of this moment) Volvo(9) Ford (3) etc etc

Without manually creating the variables up front for each vehicle type (avoid future flow maintenance) and doing an increment step, how can I do this in FLow?

 

I am stuck on 'composing' in the flow that will return a count value of each VehicleModel, and appreciate the assist!

 

End goal is to pop into my HTML table something as follows:

Volvos in the Fleet - 9

Fords in the Fleet -3

Kias in the Fleet -2

 

Many thanks!

Categories:
I have the same question (0)
  • Verified answer
    Paulie78 Profile Picture
    8,422 Moderator on at

    Check out this video I did for someone else very recently. It demonstrates a very efficient method:

     

    https://youtu.be/v8B3zZDvs5g

  • MrAutomate Profile Picture
    206 on at

    Paulie78, Many thanks for the video. 

     

    Way above my understanding , I am afraid ..  In your example, you predefined the 1st step as an array, is that right and if so, the values can be 1 of 26 letters in the alphabet?  Problem is, I can't predict what makes we may add to the fleet in the future right ? (also, not really wanting to manually build an array of potential vehicles )

     

    Does anyone in the community have a simple solution to accomplish this using the get items of the vehicles we currently have? 

     

    I would think counting an occurrence would not be this difficult, but all posts I have seen seem to involve complicated steps...  Thanks all...

  • Verified answer
    v-bofeng-msft Profile Picture
    on at

    Hi @MrAutomate :

    @Paulie78  does provide an excellent solution. The variable defined at the beginning just defines a data source for testing. On your side, you can directly use get items to obtain data without defining such a variable.

    Here is the detailed steps, if it helps, please consider marking @Paulie78 's answer as solution.

    vbofengmsft_1-1645595257534.png

    vbofengmsft_2-1645595366476.png

    concat(item()['VehicleModel'],'in the Fleet - ',length(xpath(xml(outputs('Compose')),concat('//Array[VehicleModel/text()="',item()['VehicleModel'],'"]'))))

    The Result

    vbofengmsft_0-1645595236832.png

     

    Best Regards,

    Bof

     

  • AJL90 Profile Picture
    2 on at

    Hi, I have tried both versions of these solutions and both times I hit the an error on the final step with xpath saying that it is invoking 4 parameters instead of the expected 2. It works if you hardcode the search term in the xpath query, so it seems to be an issue with invoking the "current item" term which it keeps failing on. Any help would be appreciated.

     

     

    The execution of template action 'Select_2' failed: The evaluation of 'query' action 'where' expression '@length(xpath(xml(outputs('Compose')),'//Array[RegisteredSchool/text()="',item()['RegisteredSchool'],'"]'))' failed: 'The template language function 'xpath' expects two parameters: an XML object and an XPath expression. The function was invoked with '4' parameter(s). Please see https://aka.ms/logicexpressions#xpath for usage details.'.

  • takolota1 Profile Picture
    4,974 Moderator on at

    @AJL90 

     

    You could also try this template which includes a count of the number of records for each group as a parameter on each record. It doesn’t use any xpath.

    https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Get-Distinct-Records-amp-Counts/td-p/2191533

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard