cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ramole
Memorable Member
Memorable Member

GroupBy

Hi 

I would my GroupBy to show latest entries on top the gallery please hare is the formula 

 


AddColumns(
GroupBy(AddColumns(
If(
FilterGallery_9.Selected.Filter <> "Open" && !IsBlank(TextSearchBox_8.Text),/*Case1*/
Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_2.Text in Phone || TextSearchBox_2.Text in Priority.Value || TextSearchBox_2.Text in Deadline),
FilterGallery_9.Selected.Filter = "All" && !IsBlank(TextSearchBox_8.Text),/*Case2*/
Filter(colMissedCalls,TextSearchBox_8.Text in Status.Value || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_8.Text in Phone || TextSearchBox_8.Text in Deadline),
FilterGallery_9.Selected.Filter = "All" && IsBlank(TextSearchBox_8.Text),/*Case3*/
colMissedCalls,
FilterGallery_9.Selected.Filter <> "All" && IsBlank(TextSearchBox_8.Text),/*Case4*/
Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter)),
"Comppanyvalue",Title),"Comppanyvalue","NewGroup"),"Status",
First(Sort(NewGroup, Status.Value, Descending)).Status.Value,"TIME", First(Sort(NewGroup,Time, Descending).Time),"CreatedDate",
First(Sort(NewGroup,Created, Descending)).Created,"Phone",
First(Sort(NewGroup, PhoneNumber, Descending)).PhoneNumber)  

Thank you
If this post helps, then please consider Accept it as the solution to help the others and consider giving it a "Thumbs Up."
1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @Ramole :

Could you tell me:

Do you want the sort the entire result of your code by CreatedDate, or  sort the records in NewGroup by Created?

Case1:Sort the entire result of your code by CreatedDate

Please try this code:

 

Sort(
    AddColumns(
         GroupBy(
             AddColumns(
                   If(FilterGallery_9.Selected.Filter <> "Open" && !IsBlank(TextSearchBox_8.Text),/*Case1*/
                      Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_2.Text in Phone || TextSearchBox_2.Text in Priority.Value || TextSearchBox_2.Text in Deadline),
                      FilterGallery_9.Selected.Filter = "All" && !IsBlank(TextSearchBox_8.Text),/*Case2*/
                      Filter(colMissedCalls,TextSearchBox_8.Text in Status.Value || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_8.Text in Phone || TextSearchBox_8.Text in Deadline),
                      FilterGallery_9.Selected.Filter = "All" && IsBlank(TextSearchBox_8.Text),/*Case3*/
                      colMissedCalls,
                      FilterGallery_9.Selected.Filter <> "All" && IsBlank(TextSearchBox_8.Text),/*Case4*/
                      Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter)
                      ),
                    "Comppanyvalue",
                    Title),
         "Comppanyvalue",
         "NewGroup"),
    "Status",
    First(Sort(NewGroup, Status.Value, Descending)).Status.Value,
    "TIME",
    First(Sort(NewGroup,Time, Descending).Time),
    "CreatedDate",
    First(Sort(NewGroup,Created, Descending)).Created,
    "Phone",
    First(Sort(NewGroup, PhoneNumber, Descending)).PhoneNumber
    ),
CreatedDate,
Descending)  

 

Case2:Sort the records in NewGroup by Created

Please try this code:

 

AddColumns(
     GroupBy(
             AddColumns(
                   If(FilterGallery_9.Selected.Filter <> "Open" && !IsBlank(TextSearchBox_8.Text),/*Case1*/
                      Sort(Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_2.Text in Phone || TextSearchBox_2.Text in Priority.Value || TextSearchBox_2.Text in Deadline),Created,Descending),
                      FilterGallery_9.Selected.Filter = "All" && !IsBlank(TextSearchBox_8.Text),/*Case2*/
                      Sort(Filter(colMissedCalls,TextSearchBox_8.Text in Status.Value || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_8.Text in Phone || TextSearchBox_8.Text in Deadline),Created,Descending),
                      FilterGallery_9.Selected.Filter = "All" && IsBlank(TextSearchBox_8.Text),/*Case3*/
                      Sort(colMissedCalls,Created,Descending),
                      FilterGallery_9.Selected.Filter <> "All" && IsBlank(TextSearchBox_8.Text),/*Case4*/
                      Sort(Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter),Created,Descending)
                      ),
                    "Comppanyvalue",
                    Title),
         "Comppanyvalue",
         "NewGroup"),
"Status",
First(Sort(NewGroup, Status.Value, Descending)).Status.Value,
"TIME",
First(Sort(NewGroup,Time, Descending).Time),
"CreatedDate",
First(Sort(NewGroup,Created, Descending)).Created,
"Phone",
First(Sort(NewGroup, PhoneNumber, Descending)).PhoneNumber
)

 

Best Regards,

Bof

 

View solution in original post

5 REPLIES 5
cds
Impactful Individual
Impactful Individual

You will have to add Sort() or SortByColumns() to each of your If cases.

 

SortByColumns(Filter(......), Created, Descending)

Ramole
Memorable Member
Memorable Member

Hi @cds 

Where is exactly shall put it your code please 

 

Thanks 

Thank you
If this post helps, then please consider Accept it as the solution to help the others and consider giving it a "Thumbs Up."
cds
Impactful Individual
Impactful Individual

AddColumns(
GroupBy(AddColumns(
If(
Sort(Filter(Gallery_9.Selected.Filter <> "Open" && !IsBlank(TextSearchBox_8.Text), Created, Descending),
Sort(Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_2.Text in Phone || TextSearchBox_2.Text in Priority.Value || TextSearchBox_2.Text in Deadline),
Sort(Filter(Gallery_9.Selected.Filter = "All" && !IsBlank(TextSearchBox_8.Text),/*Case2*/
Filter(colMissedCalls,TextSearchBox_8.Text in Status.Value || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_8.Text in Phone || TextSearchBox_8.Text in Deadline),
FilterGallery_9.Selected.Filter = "All" && IsBlank(TextSearchBox_8.Text),/*Case3*/
colMissedCalls,
FilterGallery_9.Selected.Filter <> "All" && IsBlank(TextSearchBox_8.Text),/*Case4*/
Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter)),
"Comppanyvalue",Title),"Comppanyvalue","NewGroup"),"Status",
First(Sort(NewGroup, Status.Value, Descending)).Status.Value,"TIME", First(Sort(NewGroup,Time, Descending).Time),"CreatedDate",
First(Sort(NewGroup,Created, Descending)).Created,"Phone",
First(Sort(NewGroup, PhoneNumber, Descending)).PhoneNumber)  

 

 

 

............am not going to put them all in there for you lol

Ramole
Memorable Member
Memorable Member

Hi @cds 

Is not working the formula 

Thank you
If this post helps, then please consider Accept it as the solution to help the others and consider giving it a "Thumbs Up."
v-bofeng-msft
Community Support
Community Support

Hi @Ramole :

Could you tell me:

Do you want the sort the entire result of your code by CreatedDate, or  sort the records in NewGroup by Created?

Case1:Sort the entire result of your code by CreatedDate

Please try this code:

 

Sort(
    AddColumns(
         GroupBy(
             AddColumns(
                   If(FilterGallery_9.Selected.Filter <> "Open" && !IsBlank(TextSearchBox_8.Text),/*Case1*/
                      Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_2.Text in Phone || TextSearchBox_2.Text in Priority.Value || TextSearchBox_2.Text in Deadline),
                      FilterGallery_9.Selected.Filter = "All" && !IsBlank(TextSearchBox_8.Text),/*Case2*/
                      Filter(colMissedCalls,TextSearchBox_8.Text in Status.Value || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_8.Text in Phone || TextSearchBox_8.Text in Deadline),
                      FilterGallery_9.Selected.Filter = "All" && IsBlank(TextSearchBox_8.Text),/*Case3*/
                      colMissedCalls,
                      FilterGallery_9.Selected.Filter <> "All" && IsBlank(TextSearchBox_8.Text),/*Case4*/
                      Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter)
                      ),
                    "Comppanyvalue",
                    Title),
         "Comppanyvalue",
         "NewGroup"),
    "Status",
    First(Sort(NewGroup, Status.Value, Descending)).Status.Value,
    "TIME",
    First(Sort(NewGroup,Time, Descending).Time),
    "CreatedDate",
    First(Sort(NewGroup,Created, Descending)).Created,
    "Phone",
    First(Sort(NewGroup, PhoneNumber, Descending)).PhoneNumber
    ),
CreatedDate,
Descending)  

 

Case2:Sort the records in NewGroup by Created

Please try this code:

 

AddColumns(
     GroupBy(
             AddColumns(
                   If(FilterGallery_9.Selected.Filter <> "Open" && !IsBlank(TextSearchBox_8.Text),/*Case1*/
                      Sort(Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_2.Text in Phone || TextSearchBox_2.Text in Priority.Value || TextSearchBox_2.Text in Deadline),Created,Descending),
                      FilterGallery_9.Selected.Filter = "All" && !IsBlank(TextSearchBox_8.Text),/*Case2*/
                      Sort(Filter(colMissedCalls,TextSearchBox_8.Text in Status.Value || TextSearchBox_8.Text in Title || TextSearchBox_8.Text in Time || TextSearchBox_8.Text in Phone || TextSearchBox_8.Text in Deadline),Created,Descending),
                      FilterGallery_9.Selected.Filter = "All" && IsBlank(TextSearchBox_8.Text),/*Case3*/
                      Sort(colMissedCalls,Created,Descending),
                      FilterGallery_9.Selected.Filter <> "All" && IsBlank(TextSearchBox_8.Text),/*Case4*/
                      Sort(Filter(colMissedCalls,Status.Value = FilterGallery_9.Selected.Filter),Created,Descending)
                      ),
                    "Comppanyvalue",
                    Title),
         "Comppanyvalue",
         "NewGroup"),
"Status",
First(Sort(NewGroup, Status.Value, Descending)).Status.Value,
"TIME",
First(Sort(NewGroup,Time, Descending).Time),
"CreatedDate",
First(Sort(NewGroup,Created, Descending)).Created,
"Phone",
First(Sort(NewGroup, PhoneNumber, Descending)).PhoneNumber
)

 

Best Regards,

Bof

 

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,440)