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 III
Super User III

@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

View solution in original post

10 REPLIES 10
RandyHayes
Super User III
Super User III

@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

@RandyHayes ,

 

I'm getting the below error for gallery labels.

 

omi18_0-1613495267989.png

Best,

Omi

 

RandyHayes
Super User III
Super User III

@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

@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 III
Super User III

@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
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 III
Super User III

@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
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 III
Super User III

@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

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (20,584)