Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 7aH8IlhsVGLwyrGxZvYJBS
Power Apps - Building Power Apps
Answered

Show unique values in a data table

Like (0) ShareShare
ReportReport
Posted on 16 Oct 2020 10:56:54 by 195

Hi all

 

I have a Sharepoint list with the following values:

Year   Test       Scenario

2019    Test A      Scen-A

2019    Test A      Scen-B

2020    Test B      Scen-C

 

In Powerapps, I have a dropdown that filters the Year column to show only distinct values (2019 & 2020). This is fine.

 

What I then need though is a data table, displaying only 2 columns (Year & Test), where the Year is equal to the dropdown value selected, but only shows the unique combinations of Year and Test.

 

So, selecting 2019 from the dropdown I need to display a datable with only one row, showing:

 

Year   Test    

2019    Test A 

 

If that can't be done - then actually just a table showing unique Test values would be fine (so just showing Test A in this example - as the dropdown would show the year already).

 

Can anyone help with how I need to do this please? I've been looking at GroupBy, but can't seem to work out the syntax required for the Data Table Items property.

 

Many thanks...

Paul

 

 

  • WarrenBelz Profile Picture
    146,889 Most Valuable Professional on 10 Jul 2023 at 08:50:34
    Re: Showing Unique Value using Distinct

    @ffabdon ,

    You would need something like

    AddColumns(
     GroupBy(
     AddColumns(
     Filter(
     DataSource,
     Asset = SearchFld_1.Selected.Value
     ),
     "InsuranceID",
     Left(INSURANCE_ID, 10)
     ),
     "InsuranceID",
     "Data"
     ),
     "Asset",
     First(Data).ASSET"
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • ffabdon Profile Picture
    4 on 10 Jul 2023 at 07:49:08
    Re: Showing Unique Value using Distinct

    Thank you @WarrenBelz but it didnt work for me? 😞 maybe i did it wrong?

    My current table was the result of this code:

    Filter(
    tblInsurance,
    ASSET=SearchFld_1.Selected.Value
    )

    The value of my SearchFld_1.Selected.Value = "ABCD"

     

    The name of the first column

    CURRENT TABLE

     

    INSURANCE_ID

    ASSET

    HU-01-2023-Insr

    ABCD
    HU-01-2023-InsrABCD
    HU-01-2023-PAsrABCD
    WI-O1-2023-InsrABCD
    WI-O1-2023-OAsrABCD
    SC-09-2023-InsrABCD
    SC-09-2023-BAsrABCD
  • WarrenBelz Profile Picture
    146,889 Most Valuable Professional on 10 Jul 2023 at 07:36:13
    Re: Showing Unique Value using Distinct

    @ffabdon ,

    You have not included any field names - so use yours where I have first and second

    AddColumns(
     GroupBy(
     AddColumns(
     DataSource,
     "NewField",
     Left(FirstFieldName, 10)
     ),
     "NewField",
     "Data"
     ),
     "OtherField",
     First(Data).SecondFieldName"
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • ffabdon Profile Picture
    4 on 10 Jul 2023 at 07:29:41
    Showing Unique Value using Distinct

    Hi,

    I am desperately in need of your help please. can you please advise how i can use distinct for below?

     

    CURRENT TABLE

     

    HU-01-2023-Insr

    ABCD
    HU-01-2023-InsrABCD
    HU-01-2023-PAsrABCD
    WI-O1-2023-InsrABCD
    WI-O1-2023-OAsrABCD
    SC-09-2023-InsrABCD
    SC-09-2023-BAsrABCD

     

    I wanted to have as a RESULT,

    HU-01-2023ABCD
    WI-O1-2023ABCD
    SC-09-2023ABCD


    Looking forward to your help please

  • PJBruen Profile Picture
    195 on 16 Oct 2020 at 13:21:18
    Re: Show unique values in a data table

    Hi,

     

    Many thanks for your suggestion. I've now found an alternative solution which was: 

    On the Items property of the Data Table, simply put: First(Filter(DataSource, Title=Dropdown.selectedText.value))

     

    For the scenario I had, this suits the requirement.

     

    Thanks again though.

    Paul

  • Verified answer
    PJBruen Profile Picture
    195 on 16 Oct 2020 at 13:19:48
    Re: Show unique values in a data table

    Hi

     

    Thanks for your help. It's much appreciated, as this has had me spinning for hours.

     

    I actually came across another solution which should work well enough for now, which didn't require the creation of a collection in this case.

     

    On the Items property of the Data Table, simply put: First(Filter(DataSource, Title=Dropdown.selectedText.value))

     

    Thanks again.

     

  • mdevaney Profile Picture
    29,987 Super User 2025 Season 1 on 16 Oct 2020 at 12:44:46
    Re: Show unique values in a data table

    @PJBruen 

    There are no silly questions here my friend.  Ask away!  Please use my code in the OnChange property of the DataTable.  

     

    Then put the collection in the Items property of the data table like this.

     

    colDataTable

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • PJBruen Profile Picture
    195 on 16 Oct 2020 at 12:30:01
    Re: Show unique values in a data table

    Hi,

     

    Many thanks for your reply, unfortunately I can't seem to get it to work though......are you able to see where I'm going wrong?

     

    Firstly, the ClearCollect statement. Should that go on a button or on the change of the dropdown selection.....or does it go on the Items property of the Data Table?

     

    Sorry - I'll ask some silly questions as I'm going around in circles with this one.

     

    Thanks,

    Paul

     

  • timl Profile Picture
    35,018 Super User 2025 Season 1 on 16 Oct 2020 at 11:43:36
    Re: Show unique values in a data table

    Hi @PJBruen 

    Just to add to @mdevaney's  reply and to suggest something else without using ForAll, you should just be able to return a single column table with the distinct tests like so:

     

    Distinct(Filter(Scenarios, ThisRecord.Year= cboYear.Selected.Value),Test)

     

    If you want to add the year column back in, here's the formula you would use:

     

     

    AddColumns(Distinct(Filter(Scenarios, ThisRecord.Year= cboYear.Selected.Value),Test),
     "Year",
     cboYear.Selected.Value
    )
    

     

  • mdevaney Profile Picture
    29,987 Super User 2025 Season 1 on 16 Oct 2020 at 11:21:57
    Re: Show unique values in a data table

    @PJBruen 

    My idea is to do this and put the data into a collection called colDataTable


    ClearCollect(colDataTable, ForAll(Distinct(ShowColumns(Filter(your_datasource_name, Year=Dropdown_Year.Selected,Value), “Year”, “Test”), ThisRecord), ThisRecord.Result)

     

     

    Here’s a simpler example of how to get the unique records in a collection.

     

    https://matthewdevaney.com/powerapps-collections-cookbook/unique-records-in-a-collection/

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 48 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 41 Super User 2025 Season 1

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 36

Overall leaderboard
Loading started