cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
omi18
Post Patron
Post Patron

Gallery Filter, Distinct, Sort, Search

Hello,

 

I'm trying to apply a distinct function to a gallery. but I'm missing something. below is my current formula. 

 

Sort(Search(Distinct(Filter('Office', Department = ListDeptBox.Selected.Abriviation),email1).Result),ListSearchBox.Text,"ID","CName","Fname"),Fname,Ascending)

 

If I remove the distinct function from the formula above, everything is working fine.

 

Thanks,

Omi

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@omi18 

So this still goes back to my original dilema...if you Distinct that example I gave before and want to use the Column1 value...which would you use?

You can group your data by the Person, but you would then be dealing with then not being able to determine what value of a project you need to display. Perhaps that is not important.

 

You can consider the following:

On your Items property of the Combobox, set it to:

AddColumns(
    GroupBy(yourDataSource,
        "yourDepartmentColumnName",
        "_records"
    ),
    "_distinctPeople",
    GroupBy(_records,
        "yourPersonColumnName",
        "_projects"
    )
)

Then set your Gallery Items property to:

yourCombobox.Selected._distinctPeople

 

_distinctPeople will be a table of two columns - one is yourPersonColumnName and the other is called _projects and will be a table of all the projects that match the person.

 

I'm still unclear on exactly what your goal is, so this may or may not be your solution. But, this will give you a distinct capability without losing the data associated with the distinct function. 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

10 REPLIES 10
RandyHayes
Super User
Super User

@omi18 

Distinct returns a table with only ONE column called Result.  If you use that in your formula, then you will not have any fields to sort or filter on.

Please consider changing your Formula to the following:

Distinct(
    Sort(
        Search(
           Filter('Office', Department = ListDeptBox.Selected.Abriviation),
           ListSearchBox.Text,"ID","CName","Fname"
        ),
        Fname,Ascending
    ),
    email1
)

Keep in mind that this still will return only a table with a single column called result (perhaps that is what you want), but the Search and sort will now work for you.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes ,

 

I'm getting the below error for gallery labels.

 

omi18_0-1613495267989.png

Best,

Omi

 

RandyHayes
Super User
Super User

@omi18 

Keep in mind that this still will return only a table with a single column called result (perhaps that is what you want), but the Search and sort will now work for you.

You will not have an Fname column in your gallery...only a Result column.

 

Using Distinct implies that you are trying to only have a list of unique information.  If you "distinct" a list, none of the other columns play into it.  If you have a table like this:

Title Column1
A 2
B 4
B 6
A 7

And you "Distinct" on Title, you would have two records: A and B.   If you then wanted to refer to a Column1 value, how would you know which one to refer to?  For A - 2 or 7?  for B - 4 or 6?

 

This is the thing about Distinct and perhaps why this is not the right function for your purpose.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes ,

 

Thanks for clearing my thoughts about distinct function. Is there any other way I can use to accomplish the logic? 

 

Best,

Omi

RandyHayes
Super User
Super User

@omi18 

Well, the thing is, I don't know what your logic is?  What are you trying to accomplish? 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
omi18
Post Patron
Post Patron

@RandyHayes ,

 

I have a table called "office" in which I have people's details working or have worked on different projects from different departments. 

 

On the app's screen, I have Combobox to filter department and a text box to search specific employees. Now what is happening, when I select the department from Combobox, the gallery shows multiple entries for a single employee. this is where I want to use a distinct function. 

 

Best,

Omi

RandyHayes
Super User
Super User

@omi18 

Is your combobox multi-select or single select?

 

When you say that you have multiple entries for a single employee, is that because it is a different department or different project?

What is it that you ultimately want to display in your gallery?

Perhaps a screenshot might help some too.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
omi18
Post Patron
Post Patron

@RandyHayes ,

 

Combobox is set to single select. 

 

Multiple entries because: from the same department: a single person working on multiple projects. I just want to display unique people from each department. 

 

omi18_2-1613502896092.png

Best,

Omi

 

 

 

RandyHayes
Super User
Super User

@omi18 

So this still goes back to my original dilema...if you Distinct that example I gave before and want to use the Column1 value...which would you use?

You can group your data by the Person, but you would then be dealing with then not being able to determine what value of a project you need to display. Perhaps that is not important.

 

You can consider the following:

On your Items property of the Combobox, set it to:

AddColumns(
    GroupBy(yourDataSource,
        "yourDepartmentColumnName",
        "_records"
    ),
    "_distinctPeople",
    GroupBy(_records,
        "yourPersonColumnName",
        "_projects"
    )
)

Then set your Gallery Items property to:

yourCombobox.Selected._distinctPeople

 

_distinctPeople will be a table of two columns - one is yourPersonColumnName and the other is called _projects and will be a table of all the projects that match the person.

 

I'm still unclear on exactly what your goal is, so this may or may not be your solution. But, this will give you a distinct capability without losing the data associated with the distinct function. 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,379)