cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tamer66
Helper IV
Helper IV

DISTINCT with sort, if and filter

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

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4

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!
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi

 

thanks for your cool support. This helps me realy.

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
)
)

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,043)