cancel
Showing results for 
Search instead for 
Did you mean: 
rsaikrishna

Get Unique Values from SharePoint List, group by the items and send notification by using Power Automate

Use Case:  There is a SharePoint list "Visitors Information" which tracks the users, department, time in and time out. We would like to send a weekly report on the number users visited each department.

rsaikrishna_1-1594927723119.png

What you will learn from this blog: Power Automate Data Operations to get unique values and grouping items by specific column

 

SharePoint List Schema:

4.JPG

The above list contains:

Visitor Name : Single line of Text

Department Visiting: Single line of Text

TimeIn: Date and Time

TimeOut : Date and Time

 

Power Automate

 

Step 1: Created a Schedule flow which runs every Saturday.

 

 

1.JPG

 

Get Items : Retrieves the visitor information from "VisitorInfo" list who visited during last 7 days.

 

In the Filter Query, you can see an expression:

 

 

 

 

TimeIn ge '@{addDays(utcNow(),-7)}' and TimeIn le '@{utcNow()}'

 

 

 

 

 

Step 2:  Get unique department names

 

rsaikrishna_0-1594926087268.png

 

Select Departments:   This is Select data operation.

From: value property from Get Items

Map:  Mapping the value "Department Visiting" to "DeptName"

 

Compose Union of Departments: To get unique department names

Use following expression:

 

 

union(body('Select_Departments'),body('Select_Departments'))

 

 

 

Step 3: Create string variable

varHtmlTableRows is a string variable to store all the department name and no. of visitors in HTML tags.

 

rsaikrishna_1-1594926340174.png

 

Step 4: Loop thru each department to get no. of visitors

 

Note: We are not reading the SharePoint list for every department name. If we do that, it is a performance hit. We already have all the visitor information from Get Items action in Step 1.

 

rsaikrishna_2-1594926559042.png

 

Select an output from previous steps: Outputs is the value from "Compose union of departments" action created in Step 3.

 

Filter array: 

a. value is the value from Get Items action created in Step 1.

b. Comparing "Department Visiting" is equal to Output of "Current Department Name" action.

 

Append to string variable:

We are creating HTML table row for each department and appending it to the string variable varHtmlTableRows.

Outputs is the value from "Current Department Name" action.

 

 

<tr><td>@{outputs('Current_Department_Name')}</td><td align='center'>@{length(body('Filter_array'))}</td></tr>

 

 

 

 

Step 5: 

Checking if varHtmlTableRows is null or empty. If this variable is empty or null, then there are no visitor items.

 

rsaikrishna_1-1594927398663.png

 

Compose HTML Style: Using this style while sending email for table.

 

 

 

<style>
table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  text-align: left;
  padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}

th {
  background-color: #4CAF50;
  color: white;
}
</style>

 

 

 

 

Expanded "Send an email (V2)" action screen shot:

 

rsaikrishna_2-1594927495620.png

Note: In the body field, the first Outputs is from compose action named as "Compose HTML Style" and second Outputs is from compose action named as  "Construct HTML table".

 

Here is the output email:

rsaikrishna_0-1594927683107.png

Regards

Krishna Rachakonda

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/