Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Grouping data

(0) ShareShare
ReportReport
Posted on by 345

Morning all,

 

I'm sure that I don't understanding GroupBy and AddColumns enough to be doing this, so to save myself running in circles and throwing stuff at the wall to see what sticks, I thought I would seek some guidance. I have a sharepoint list that I'm filtering into a collection to remove all blank rows. the resulting data looks like this:

 

4.PNG

Now what I need is create a list of distinct Items, where item selected to keep has the closest date to today. So far I've tried to group them by Item but i get [Object object] errors when i try to display them in a data table:

 

ClearCollect(
 calendarCol,
 GroupBy(
 AddColumns(
 Filter(
 calPre,
 Not(IsBlank(FAQ_x0020_Item_x0020_Name))
 ),
 "Itm",
 Text('FAQ Item Name'.Value),
 "Mon",
 First(
 Sort(
 Filter(
 calPre,
 Month >= Today()
 ),
 Month,
 Ascending
 )
 ).Month
 ),
 "Itm",
 "Mon"
 )
)

 

7.PNG

I feel like I might be almost there but I can't figure out how to make GroupBy and AddColumns works. 

 

Any help would be appreciated

  • EpicTriffid Profile Picture
    345 on at
    Re: Grouping data

    Hi @WarrenBelz Yes, It did thankyou! I'll mark it as a solution now!

  • WarrenBelz Profile Picture
    146,605 Most Valuable Professional on at
    Re: Grouping data

    Hi @EpicTriffid ,

    Just checking if you got the result you were looking for on this thread. Happy to help further if not.

    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.

  • Verified answer
    WarrenBelz Profile Picture
    146,605 Most Valuable Professional on at
    Re: Grouping data

    Thanks @EpicTriffid ,

    I see what you are doing now - just had to get my mind around the logic. Firstly if you use a data table (rather than a gallery), you will need to delete the "Data" field as it will be a table. As well, what type of field is 'FAQ Item Name'?

    If it is a Single line of Text, you can do this

    ClearCollect(
     calendarCol,
     AddColumns(
     GroupBy(
     RenameColumns(
     Filter(
     calPre,
     !IsBlank(FAQ_x0020_Item_x0020_Name)
     ),
     "FAQ_x0020_Item_x0020_Name",
     "Item"
     ),
     "Item",
     "Data"
     ),
     "Mon",
     First(
     Sort(
     Data,
     Month
     )
     ).Month
     )
    )

    If it is a Choice field, you will need this

    ClearCollect(
     calendarCol,
     AddColumns(
     GroupBy(
     AddColumns(
    		 Filter(
     calPre,
     !IsBlank(FAQ_x0020_Item_x0020_Name.Value)
     ),
     "Item",
     FAQ_x0020_Item_x0020_Name.Value
     )
     "Item",
     "Data"
     ),
     "Mon",
     First(
     Sort(
     Data,
     Month
     )
     ).Month
     )
    )

     

    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.

     

  • EpicTriffid Profile Picture
    345 on at
    Re: Grouping data

    Hi @WarrenBelz,

     

    Thanks for the reply. The above makes sense in terms of it not having anything to take all the grouped fields. However, while it is now giving me a distinct list with dates, all the dates are set to tomorrow (13/04/2021), like below:

     

    7.PNG

     

    Thinking that my method of getting only those items with the soonest occurring date was incorrect, i set a variable to work out a month from now and added that into my filter (I also changed the fields name of Itm and Mon to make it easier to understand:

     

    Set(nextMonth, DateAdd(Today(), 1, Months)); 
    
    ClearCollect(
     calendarCol,
     GroupBy(
     AddColumns(
     Filter(
     calPre,
     !IsBlank(FAQ_x0020_Item_x0020_Name)
     ),
     "FAQItem",
     Text('FAQ Item Name'.Value),
     "dateMonth",
     First(
     Sort(
     Filter(
     calPre,
     And(Month >= Today(), Month <= nextMonth)
     ),
     Month,
     Ascending
     )
     ).Month
     ),
     "FAQItem",
     "dateMonth",
     "Data"
     )
    )

     

    However, this gives the same thing of tomorrows date for all items. I would assume I've made an error in using First but I'm not how to get around it as i can't seem to return any date value without wrapping date in First.

  • WarrenBelz Profile Picture
    146,605 Most Valuable Professional on at
    Re: Grouping data

    Hi @EpicTriffid ,

    You need to add a final column to the GroupBy() to take all the grouped fields (or it will assume Mon is it).  Also Month is not a good name for a Field as it is a Reserved Word in Power Apps.

    ClearCollect(
     calendarCol,
     GroupBy(
     AddColumns(
     Filter(
     calPre,
     !IsBlank(FAQ_x0020_Item_x0020_Name)
     ),
     "Itm",
     'FAQ Item Name',
     "Mon",
     First(
     Sort(
     Filter(
     calPre,
     Month >= Today()
     ),
     Month,
     Ascending
     )
     ).Month
     ),
     "Itm",
     "Mon",
     "Data"
     )
    )

     

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,605 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,946 Most Valuable Professional

Leaderboard