cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to create send Email flow which including a Privot Table summary report from the Sharepoint List.

Hi, I'm very new for this community and just beginning learn by myself for Power automate.

I have my project to ask every professional users here.

 

Steps

1. I already have a survey form created on MS Forms (form including Score to calculate)

2. I already have a Automate flow to keep all responses to Sharepoint list.

theerayp_3-1675054165607.png

 

3. I need to know how to create send Email flow which including a Privot Table summary report from the Sharepoint List.

 

Example for Email that I need.

theerayp_2-1675054118399.png

 

PS. I tried to use Power BI but It's doesn't work because I don't have a Premium license that can't use for this function.

Can someone please give me an advise ,

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

Because your Trainer column is of type Choice, we would need to change the expressions within the Select action. See updated expressions.

 

//From
union(xpath(outputs('XML'), '//root/value/Trainer/Value/text()'), xpath(outputs('XML'), '//root/value/Trainer/Value/text()'))

//Survey Class Score
formatNumber(xpath(outputs('XML'), concat('sum(//root/value[Trainer/Value="', item(), '"]/SurveyClass/text()) div count(//root/value[Trainer/Value="', item(), '"]/SurveyClass/text())')), 'N2')

//Survey Trainer Score
formatNumber(xpath(outputs('XML'), concat('sum(//root/value[Trainer/Value="', item(), '"]/SurveyTrainer/text()) div count(//root/value[Trainer/Value="', item(), '"]/SurveyTrainer/text())')), 'N2')

 


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

View solution in original post

5 REPLIES 5

@Anonymous A few questions for you.

 

  1. Are the Class and Trainer list columns just text columns, or choice columns?
  2. What would you display in your Pivot Table if a trainer was across multiple classes? For example, if Mr. D taught Class A4 and A7? I'm assuming it would calculate the average across all their classes.
  3. How many items would you expect to be in your SharePoint List over the next couple of years?
  4. Would you only want to use the data from the current month using Survey Date?

Just working on a solution for you now.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.
Anonymous
Not applicable

Hi, @grantjenkins 

 

Thanks for replying me, and here are the answers for your questions.

 

1. Are the Class and Trainer list columns just text columns, or choice columns?
    It's Choice columns.
2. What would you display in your Pivot Table if a trainer was across multiple classes? For example, if Mr. D taught Class A4 and A7?
   The result would be show only Mr. D and the Score of 2 classes are average.
3. How many items would be in your SharePoint List?
   There's only this item in this list.
4. Would you want to only get a certain number of items based on some criteria? I would assume the list would grow over time.
  Now I have only this item in the list, and in the future I would create some flow to clear the record every 2 Months to prevent the file from becoming too large. 

 

Hopefully this is what you're looking for. Note that I convert the JSON data to XML as part of the flow so we can use XPath to calculate across the rows.

 

For this example, I've used the following list. Class is using the Title field (renamed to Class). Trainer is Single line of text. Survey Class and Survey Trainer are Number. Note that I added a couple of extra rows (A5) that happened last month, so won't be used in the flow.

grantjenkins_0-1675065973319.png

 

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

grantjenkins_1-1675066095653.png

 

Get items will retrieve all the items where the Survey Date is the current month. It uses the following expression for the Filter Query. The expressions get the start of the current month and the start of the following month and check that the Survey Date is between those dates.

SurveyDate ge '@{startOfMonth(utcNow())}' and SurveyDate lt '@{startOfMonth(addToTime(utcNow(), 1, 'month'))}'

grantjenkins_2-1675066240118.png

 

By default, Get items will only return a maximum of 100 items. If you have a lot (or expect to have a lot) of items in your list, you will need to go into Settings, turn on Pagination, and set a Threshold larger than the number of items you would expect to have in your list over the next few years.

grantjenkins_3-1675066370154.png

grantjenkins_4-1675066378987.png

 

XML (Compose) converts the data returned from Get items to XML so we can use XPath expressions. This makes it much easier to perform calculations across rows (removes the need for loops). The expression used is:

xml(json(concat('{"root": { value:', outputs('Get_items')?['body/value'], '}}')))

grantjenkins_5-1675066607579.png

 

Select is where we build the data for our table. Below are the expressions used. XPath in Power Automate is still a bit limited and doesn't include the average (avg) function, so we need to divide the sum by the count to get the average. We use formatNumber with 'N2' so our averages come back as numbers with 2 decimal places.

//From - gets the list of trainers and uses union to remove duplicates
union(xpath(outputs('XML'), '//root/value/Trainer/text()'), xpath(outputs('XML'), '//root/value/Trainer/text()')) 

//Trainer
item()

//Survey Class Score
formatNumber(xpath(outputs('XML'), concat('sum(//root/value[Trainer="', item(), '"]/SurveyClass/text()) div count(//root/value[Trainer="', item(), '"]/SurveyClass/text())')), 'N2')

//Survey Trainer Score
formatNumber(xpath(outputs('XML'), concat('sum(//root/value[Trainer="', item(), '"]/SurveyTrainer/text()) div count(//root/value[Trainer="', item(), '"]/SurveyTrainer/text())')), 'N2')

 grantjenkins_6-1675066869810.png

 

The Select above provides us with the scores for each trainer. However, we still need to calculate the average scores across all trainers. Total (Compose) builds a single object within an array, retrieving the totals using the following expressions.

formatNumber(xpath(outputs('XML'), concat('sum(//root/value/SurveyClass/text()) div count(//root/value/SurveyClass/text())')), 'N2')

formatNumber(xpath(outputs('XML'), concat('sum(//root/value/SurveyTrainer/text()) div count(//root/value/SurveyTrainer/text())')), 'N2')

 

The full code that you can copy/paste into Total is below:

[
  {
    "Trainer": "Average Score",
    "Survey Class Score": @{formatNumber(xpath(outputs('XML'), concat('sum(//root/value/SurveyClass/text()) div count(//root/value/SurveyClass/text())')), 'N2')},
    "Survey Trainer Score": @{formatNumber(xpath(outputs('XML'), concat('sum(//root/value/SurveyTrainer/text()) div count(//root/value/SurveyTrainer/text())')), 'N2')}
  }
]

grantjenkins_7-1675067097953.png

 

Create HTML table uses the union of the two arrays - Select and Total. Effectively, it combines the averages for each trainer, and the total averages across trainers.

union(body('Select'), outputs('Total'))

grantjenkins_8-1675067194409.png

 

Compose HTML table style has some CSS that will make the HTML table look nicer in the email. The CSS is below:

<style>  
    table {
        border-collapse: collapse;
    }
    table td,
    table th {
        border: 1px solid #ddd;
        padding: 6px 20px;
        text-align: center;
    }
    table td:first-child,
    table th:first-child {
        text-align: left;
    }
    table th, tr:last-child {
        background-color: #1C6EA4;
        color: white;
    }
</style>

grantjenkins_9-1675067286817.png

 

Finally, Send an email uses the output from both Compose HTML table style and Create HTML table. It also uses the following expression within the Subject and Body to display the current month.

formatDateTime(utcNow(), 'MMMM')

grantjenkins_11-1675067476109.png

 

After running the flow, we should get the following output.

grantjenkins_12-1675067547248.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

Because your Trainer column is of type Choice, we would need to change the expressions within the Select action. See updated expressions.

 

//From
union(xpath(outputs('XML'), '//root/value/Trainer/Value/text()'), xpath(outputs('XML'), '//root/value/Trainer/Value/text()'))

//Survey Class Score
formatNumber(xpath(outputs('XML'), concat('sum(//root/value[Trainer/Value="', item(), '"]/SurveyClass/text()) div count(//root/value[Trainer/Value="', item(), '"]/SurveyClass/text())')), 'N2')

//Survey Trainer Score
formatNumber(xpath(outputs('XML'), concat('sum(//root/value[Trainer/Value="', item(), '"]/SurveyTrainer/text()) div count(//root/value[Trainer/Value="', item(), '"]/SurveyTrainer/text())')), 'N2')

 


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.
Anonymous
Not applicable

Hi @grantjenkins ,

 

Thanks for your help and show me all of fully flow, that's helpful for me very much.

I done it with my flow but I've got some problem and need your help again.

 

1. The email result don't show the data in the table.

    theerayp_0-1675132069768.png

 

2. All steps are run completely without any error.

   theerayp_1-1675132176371.png

 

3. The Select step I've got the result like this.

theerayp_2-1675132293041.png

 

4. And the result of Total step like this.

theerayp_3-1675132346028.png

 

5. Here are the steps that I follow from your flow with same column name in the table.

theerayp_4-1675132548893.png

Select

//From
union(xpath(outputs('XML'), '//root/value/Trainer/Value/text()'), xpath(outputs('XML'), '//root/value/Trainer/Value/text()'))

//Survey Class Score
formatNumber(xpath(outputs('XML'), concat('sum(//root/value[Trainer/Value="', item(), '"]/SurveyClass/text()) div count(//root/value[Trainer/Value="', item(), '"]/SurveyClass/text())')), 'N2')

//Survey Trainer Score
formatNumber(xpath(outputs('XML'), concat('sum(//root/value[Trainer/Value="', item(), '"]/SurveyTrainer/text()) div count(//root/value[Trainer/Value="', item(), '"]/SurveyTrainer/text())')), 'N2')

 

Total

[
  {
    "Trainer": "Average Score",
    "Survey Class Score": @{formatNumber(xpath(outputs('XML'), concat('sum(//root/value/SurveyClass/text()) div count(//root/value/SurveyClass/text())')), 'N2')},
    "Survey Trainer Score": @{formatNumber(xpath(outputs('XML'), concat('sum(//root/value/SurveyTrainer/text()) div count(//root/value/SurveyTrainer/text())')), 'N2')}
  }
]

 

6. Is it possible that the problem from Survey Class and Survey Trainer column are calculated with Average result from other columns like my sharepoint list below?

theerayp_5-1675133862383.png

 

7. The Column type that I set for the table.

     Survey Class      Calculated (calculation based on other columns)
     Survey Trainer   Calculated (calculation based on other columns)

     Class Score...     Number

 

---

Thank you.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (765)