Data - How to hide duplicate rows in a gallery / show distinct multiple columns in a gallery

There are many use-case scenarios where it's necessary to show sets of distinct values, or to hide duplicate rows. The challenge that app builders face is that the Distinct function is capable of returning distinct values from a single column only.


Therefore, this post describes a technique to hide duplicates that doesn't rely on the Distinct function.

Example of use case of showing multiple distinct columns

A typical example of where duplicates occur is when we join data from multiple tables. 

Let's take the example of a set of tables in a helpdesk type application. There are two tables in this app - an issue table, and an 'issue response' table. The issue tables stores the main details of a support ticket. Each interation with a customer is stored as a seperate record in the 'issue response' table.

The schema of these tables are shown beneath.



The requirement is to build a search screen where users can display unique issue records that match the the issue response description.

The starting point is to create a SQL Server view that joins the issue and 'issue response' tables.

CREATE VIEW vwSearchIssue
AS
SELECT
iss.IssueID,
iss.Description AS [IssueDescription],
iss.TargetCloseDateTime,
isr.Description AS [IssueResponseDesc],
isr.CreateDateTime AS [IssueResponseCreateDate]
FROM
Issue iss JOIN
IssureResponse isr
ON iss.IssueID = isr.IssueID


From Power Apps, we can build a search feature by adding search text box, and a gallery control with the Items property set to the following formula:

Search(vwSearchIssue, txtSearchInput.Text, "IssueResponseDesc")

The problem here is that if multiple matches exist in the 'issue response' table, the result will include duplicate issue details.

How to remove duplicates from a gallery control

To illustrate the problem, here's the data that the view would return if the user were to search for the word 'user' in the response description. Notice the duplicates that are highlighted in red.


To display these distinct values in a gallery control, we would call the GroupBy function to group the result by IssueID. We would set the Items property of our gallery control to this same formula.

GroupBy(Search(vwSearchIssue, txtSearchInput.Text, "IssueResponseDesc"),
"IssueID",
"Data"
)

This effectively produces a result that looks like this.

Each record in this result includes an IssueID field and a child table called 'Data' that contains all the rows that match the corresponding issue ID.

From the item template of the gallery, we can show the distinct 'Issue Description', and 'Target Close Datetime' fields by looking up the first row in the data child table. The syntax to return the IssueDescription would look like this:

First(ThisItem.Data).IssueDescription

Likewise, this would return the 'Target Close Datetime' field.
First(ThisItem.Data).TargetCloseDateTime

As the screenshot beneath shows, we can use this technique to configure our gallery control to show just the distinct IssueID, 'Issue Description', and 'Target Close Datetime' fields that relate to the search.



Note that a caveat of this method is that the GroupBy function is not delegable. In most search scenarios however, this behaviour is generally acceptable because users typically enter criteria that filters matching records to a value under 2000 rows.

Conclusion

A common requirement is to hide duplicate rows in a gallery control, or to show distinct values accross multiple columns. This post demonstrated how to carry out this task by grouping the results with the.GroupBy function.

Related posts

Data - How to remove trailing comma all rows in a table
February 20, 2025
Data - How to find the common rows from 3 or more collections
October 06, 2024
Data - How to show the distinct rows from 2 data sources or collections
February 26, 2024
Data - How to implement circular rotational date sorting
February 21, 2024
Bug - What to do when the data section of the Power Apps Maker portal doesn't work
June 18, 2023
Data - Combine columns from separate tables into a single table
October 13, 2022
Formula - Transposing/converting rows to columns- an almost impossible task?
September 23, 2021
Data - How to rename field names in a record
July 14, 2021
Data - Retrieving news/forum/blog articles with RSS
June 26, 2021
Data - How to sort by partial numbers in a text field
June 23, 2021
Data - How to return the last record from a table
June 19, 2021
Data - How to create bulk test/dummy records with random values
June 18, 2021
Data - 3 things you should know before using the MySQL or PostgreSQL connectors
May 11, 2021
Data - A walkthrough of how to migrate the data source of an app from Excel to Sharepoint
April 26, 2021
Data - How to enforce unique values (or prevent duplicate values) in one or more columns
April 19, 2021
Data - How much mobile data does Power Apps consume? What ways can we minimise this?
March 28, 2021
Data - How to save and retrieve Google calendar entries
March 14, 2021
Data - How to save and retrieve Google contacts
March 10, 2021
SQL - Caution! This is how users can hack shared SQL connections
January 23, 2021
SharePoint – 2 Mistakes to avoid when importing Excel data
January 10, 2021
SQL - Don't let this DateTime bug catch you out!
January 05, 2021
Settings - What's the purpose of the "Explicit Column Selection" Setting?
January 04, 2021
SQL Server for Beginners Part 3 - Installing On-Premises Gateway
January 24, 2019
SQL Server for Beginners Part 2 - Installing Management Studio
January 14, 2019
SQL Server for Beginners Part 1 - Installing SQL Server
January 04, 2019
Searching data–What you need to know about case sensitivity
December 27, 2018
Images - How to create images that can change depending on data
November 09, 2018
Excel - Reasons NOT to use Excel as a data source
September 25, 2018
SharePoint - What you need to know about Filtering Data
September 16, 2018
Formulas - Generating Row Numbers
April 05, 2018