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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Calculate Percentage (...
Power Automate
Answered

Calculate Percentage (urgent)

(0) ShareShare
ReportReport
Posted on by 13

Hello All,

below is my data, 

 

[
{
"SId": "63",
"Rs": "3",
"QId": "85",
"Max": 4
},
{
"SId": "63",
"Rs": "2",
"QId": "111",
"Max": 4
},
{
"SId": "64",
"Rs": "2",
"QId": "87",
"Max": 4
},
{
"SId": "64",
"Rs": "1",
"QId": "177",
"Max": 4
}
]

This is my data.
above I have SID which is 63 and 64, Now i want to add Rs and Max respectively.
For SID 63,
I want RS = 3+2=5.
I want Max 4+4=8.

Pecentage = 5/8*100

For SID 64,
I want Rs to be 2+1=3
I want Max 4+4=8.

Percentage = 3/8*100

I need an array to distinguish between the SID.

 

I hope you will help this is urgent.

Thanks

 

@Expiscornovus, @grantjenkins, @Pstork1, @ScottShearer, @Sundeep_Malik, @v-jefferni,@v-chengfen-msft , @v-liwei-msft     

 

 

Categories:
  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    @RadhikaNavkar Here you go.

     

    Full flow below. I'll go into each of the actions.

    grantjenkins_0-1670068201228.png

     

    Data is a Compose that has your raw JSON data.

    grantjenkins_1-1670068233205.png

     

    Select extracts out each of the SId values into a simple array. Note that for Map I've used text mode (see arrow on screenshot below). The expression used here is:

     

    item()?['SId']

     

    grantjenkins_6-1670068743049.png

     

    SId is a Compose that uses the union expression to remove duplicate SId values.

     

    union(body('Select'),body('Select'))

     

    grantjenkins_3-1670068374081.png

     

    XML is a Compose that converts your raw Data to XML so we can use XPath in the next step to calculate across the different objects. Note that this also adds a root element to the data so it's valid XML.

     

    xml(json(concat('{"root": { values:', outputs('Data'), '}}')))

     

    grantjenkins_4-1670068460233.png

     

    Output is a Select that takes in the output from the Compose called Sid and uses the following expressions:

     

    item()
    
    xpath(outputs('XML'), concat('sum(//values[normalize-space(SId/text())="', item(), '"]/Rs/text())'))
    
    xpath(outputs('XML'), concat('sum(//values[normalize-space(SId/text())="', item(), '"]/Max/text())'))
    
    mul(xpath(outputs('XML'), concat('sum(//values[normalize-space(SId/text())="', item(), '"]/Rs/text()) div sum(//values[normalize-space(SId/text())="', item(), '"]/Max/text())')), 100)

     

    grantjenkins_1-1670069476376.png

     

    The final output after running the flow is:

     

    [
     {
     "SId": "63",
     "Rs": 5,
     "Max": 8,
     "Percentage": 62.5
     },
     {
     "SId": "64",
     "Rs": 3,
     "Max": 8,
     "Percentage": 37.5
     }
    ]

     

     

    Hopefully that's what you're after.

  • RadhikaNavkar Profile Picture
    13 on at

    Hi, @grantjenkins,

     

    Thanks for this wonderful solution, I was stuck on this from last week. 😊 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 298 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 289

#3
Henil Profile Picture

Henil 125

Last 30 days Overall leaderboard