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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Distinct or Group By -...
Power Apps
Answered

Distinct or Group By - Complex Collection Filter needed

(0) ShareShare
ReportReport
Posted on by 301

Hi i currently use the following filter

 

If(
 Connection.Connected,
 ClearCollect(
 colAssetReg,
 {Asset: ""}
 );
 Collect(
 colAssetReg,
 Sort(
 Distinct(
 Filter(
 'Asset Register',
 Asset_x0020_Type.Value = "Haul Truck" || Asset_x0020_Type.Value = "Compactor" || Asset_x0020_Type.Value = "Dozer" 
 ),
 Asset
 ),
 Result
 )
 )
)

 

Which works to first add a blank value in Asset and then filters the collection by the 'asset type' sharepoint choice column, however i have two other columns i wish for it too filter by, One is a Text field called location and another choice field called status.

 

From my reading of the wiki i now use GroupBy correct?

 

Could someone unjumble my attempt and tell me where i went wrong (just trying with one for now)

If(
 Connection.Connected,
 ClearCollect(
 colAssetReg,
 {Asset: ""}
 );
 Collect(
 colAssetReg,
 Sort(
 GroupBy(
 Filter(
 'Asset Register',
 Asset_x0020_Type.Value = "Haul Truck" || Asset_x0020_Type.Value = "Compactor" || Asset_x0020_Type.Value = "Dozer" && Status.value = "Active"
 ),
 Asset, Status
 ),
 Result
 )
 )
)

i cant seem to make it work? how could i get the formula to work with 3 or 4 etc values? the examples in the wiki dont work for me

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @ShaneITAutomate ,

    I am guessing a bit on what you want as an output, but this will: -

    • Filter the list with those four (note the bracketing added) parameters
    • Group by Asset
    • Put the data from each group in a table on the record OtherData
    • Sort the lot by Asset
    If(
     Connection.Connected,
     ClearCollect(
     colAssetReg,
     {Asset: ""}
     );
     Collect(
     colAssetReg,
     Sort(
     GroupBy(
     Filter(
     'Asset Register',
     (
     Asset_x0020_Type.Value = "Haul Truck" || 
     Asset_x0020_Type.Value = "Compactor" || 
     Asset_x0020_Type.Value = "Dozer" 
     ) && 
     Status.value = "Active"
     ),
     "Asset", 
     "OtherData"
     ),
     Asset
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • ShaneITAutomate Profile Picture
    301 on at

    Hey Warren,

     

    Just curious for my own information could you explain to me what OtherData is in this code? currently i set everything related to the datatable to Selected.Asset which works.. but what is that group or table?

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @ShaneITAutomate ,

    You can call that whatever you want (HomerSimpson will work). When you use GroupBy(), all the records belonging to the grouped field/s then have a many-to-one relationship. This field is a table with them in with each table belonging to the particular grouped field/s. Whenever you use GroupBy(), the last field name specified will be this field (and is the only one which is free-form)

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 312

#3
Mohsin Ali Profile Picture

Mohsin Ali 252

Last 30 days Overall leaderboard