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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / DISTINCT with sort, if...
Power Apps
Answered

DISTINCT with sort, if and filter

(0) ShareShare
ReportReport
Posted on by 228

Hello,

 

i have a gallery with sort, if and filter function. Now i want use the Distinct function to show the names 

only show once.

 

SortByColumns(
 DISTINCT(If(
 !IsBlank(searchField.Text);
 Filter(
 myContracts;
 StartsWith(
 Nachname;
 searchField.Text
 ) || StartsWith(
 Mitgliedsnummer;
 searchField.Text
 )
 );
 Filter(
 myContracts;
 ArtName = DropdownGew.SelectedText.Value
 )
 );
 "Mitgliedsnummer";
 If(
 SortDescending1;
 Descending;
 Ascending
 )
);Mitgliedsnummer)

Has anyone an idea?

 

Thanks

Categories:
I have the same question (0)
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    HI @Tamer66 

     

    Can you try out the below expression to just get the distinct "Mitgliedsnummer":
     
    SortByColumns(
        DISTINCT(If(
            !IsBlank(searchField.Text);
            Filter(
                myContracts;
                StartsWith(
                    Nachname;
                    searchField.Text
                ) || StartsWith(
                    Mitgliedsnummer;
                    searchField.Text
                )
            );
            Filter(
                myContracts;
                ArtName = DropdownGew.SelectedText.Value
            )
        );
        "Mitgliedsnummer");
        Result
        If(
            SortDescending1;
            Descending;
            Ascending
        )
    )
     
    The above expression will just return a one column table with all the distinct "Mitgliedsnummer".
     
    In case you are looking for something that shows one entry per Mitgliedsnummer, then you may want to use the GroupBy function.
    SortByColumns(
        GroupBy(If(
            !IsBlank(searchField.Text);
            Filter(
                myContracts;
                StartsWith(
                    Nachname;
                    searchField.Text
                ) || StartsWith(
                    Mitgliedsnummer;
                    searchField.Text
                )
            );
            Filter(
                myContracts;
                ArtName = DropdownGew.SelectedText.Value
            )
        );
        "Mitgliedsnummer";"Grouped");
        Result
        If(
            SortDescending1;
            Descending;
            Ascending
        )
    )
     
    This will create a grouped nested array of all the records corresponding to specific Mitgliedsnummer, and if you want to fetch a specific record in your gallery, you can filter each gallery item by performing filter queries on ThisItem.Grouped
     
    Hope this Helps!

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
  • Verified answer
    v-xida-msft Profile Picture
    on at

    Hi @Tamer66 ,

    Do you want to show distinct Mitgliedsnummer value within your Gallery?

    Do you want to only show Mitgliedsnummer value within your Gallery?

     

    Based on the formula that you provided, I think there is something wrong with it. I have made a test on my side, please consider take a try with the following workaround:

    1. If you just want to show Mitgliedsnummer value within your Gallery:

     Set the Items property of the Gallery to following formula:

    Distinct(
    SortByColumns( If( !IsBlank(searchField.Text); Filter( myContracts; StartsWith(Nachname; searchField.Text) || StartsWith(Mitgliedsnummer; searchField.Text) ); Filter( myContracts; ArtName = DropdownGew.SelectedText.Value ) ), "Mitgliedsnummer"; If(SortDescending1; Descending; Ascending) ),
    "Mitgliedsnummer"
    )

     

    2. If you want to show distinct Mitgliedsnummer value along with other column values within your Gallery, I think an nested Gallery and GroupBy function could achieve your needs:

    Set the Items property of the Outer Gallery (Parent Gallery, Gallery1) to following:

    GroupBy(
    SortByColumns( If( !IsBlank(searchField.Text); Filter( myContracts; StartsWith(Nachname; searchField.Text) || StartsWith(Mitgliedsnummer; searchField.Text) ); Filter( myContracts; ArtName = DropdownGew.SelectedText.Value ) ), "Mitgliedsnummer"; If(SortDescending1; Descending; Ascending) ),
    "Mitgliedsnummer",
    "GroupData"
    )

    Then within the Outer Gallery, add a nested Gallery (Gallery2), set the Items property to following:

    ThisItem.GroupData

    within the nested Gallery, you could add some Label controls to display other column values from your "myContracts" data source using the following formula:

    ThisItem.Nachname
    ThisItem.ArtName

    ...

     

    Please take a try with above solution, then check if the issue is solved.

     

    Best regards,

  • Tamer66 Profile Picture
    228 on at

    Hi

     

    thanks for your cool support. This helps me realy.

  • David8 Profile Picture
    89 on at

    I have tried following the example shown here because I have exactly the same issue. I am trying to get only distinct values. The formula below works perfectly but when I try to use Distinct, I am unable to get any results. Could someone help me please identify what I am doing wrong?

     

    SortByColumns(
    Filter(
    'Vendor List',
    TextSearchBox1.Text in ID || TextSearchBox1.Text in Title || TextSearchBox1.Text in Tier.Value || TextSearchBox1.Text in 'Vendor Status'.Value || TextSearchBox1.Text in 'Vendor Posture'.Value || TextSearchBox1.Text in 'SVM Analyst'.DisplayName
    ),
    "Title",
    If(
    SortDescending1,
    Descending,
    Ascending
    )
    )

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard