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 / unable to sort by mont...
Power Apps
Unanswered

unable to sort by months in powerapps

(0) ShareShare
ReportReport
Posted on by 102

I have the below formulas in the App onstart property so that it creates these collections filters them and sorts them by month. Then I Concatenate all sorted month collections into a final collection (ShuffledNames) for display in my gallery. The issue is in the sort part where I keep getting the function sort has some invalid arguments. Any help will be mych appreciated

 

ClearCollect(
FilteredRecords,
Filter(
'ES year to year dash',
'Date of mention' >= DateAdd(Today(), -8, TimeUnit.Months)
)
);
ClearCollect(
Month1Records,
Filter(
FilteredRecords,
Month('Date of mention') = Month(Today()) && Year('Date of mention') = Year(Today())
)
);

ClearCollect(
Month2Records,
Filter(
FilteredRecords,
Month('Date of mention') = Month(DateAdd(Today(), -1, TimeUnit.Months)) && Year('Date of mention') = Year(DateAdd(Today(), -1, TimeUnit.Months))
)
);
ClearCollect(
Month3Records,
Filter(
FilteredRecords,
Month('Date of mention') = Month(DateAdd(Today(), -2, TimeUnit.Months)) && Year('Date of mention') = Year(DateAdd(Today(), -2, TimeUnit.Months))
)
);
ClearCollect(
Month4Records,
Filter(
FilteredRecords,
Month('Date of mention') = Month(DateAdd(Today(), -3, TimeUnit.Months)) && Year('Date of mention') = Year(DateAdd(Today(), -3, TimeUnit.Months))
)
);

ClearCollect(
Month5Records,
Filter(
FilteredRecords,
Month('Date of mention') = Month(DateAdd(Today(), -4, TimeUnit.Months)) && Year('Date of mention') = Year(DateAdd(Today(), -4, TimeUnit.Months))
)
);

ClearCollect(
Month6Records,
Filter(
FilteredRecords,
Month('Date of mention') = Month(DateAdd(Today(), -5, TimeUnit.Months)) && Year('Date of mention') = Year(DateAdd(Today(), -5, TimeUnit.Months))
)
);

ClearCollect(
Month7Records,
Filter(
FilteredRecords,
Month('Date of mention') = Month(DateAdd(Today(), -6, TimeUnit.Months)) && Year('Date of mention') = Year(DateAdd(Today(), -6, TimeUnit.Months))
)
);

// Repeat for each month within the last 8 months...
// ClearCollect to create sorted collections for each month
ClearCollect(
SortedMonth1,
Sort(
Filter(
FilteredRecords,
Month('Date of mention') = Month(Today()) && Year('Date of mention') = Year(Today())
),
Descending,
'Date of mention'
)
);

ClearCollect(
SortedMonth2,
Sort(
Filter(
FilteredRecords,
Month('Date of mention') = Month(DateAdd(Today(), -1, Months)) && Year('Date of mention') = Year(DateAdd(Today(), -1, Months))
),
Descending,
'Date of mention'
)
);
ClearCollect(
ShuffledNames,
Concat(
SortedMonth1,
SortedMonth2,
// Include other sorted month collections here...
)
)

Categories:
  • timl Profile Picture
    37,314 Super User 2026 Season 2 on at

    Hi @BianceBee 

    In the call to Sort, the sort column/expression and sort order arguments are mixed up. The second argument is the column and the third argument is the sort order. The formula should look more like this:

    ClearCollect(
     SortedMonth1,
     Sort(
     Filter(
     FilteredRecords,
     Month('Date of mention') = Month(Today()) 
     && Year('Date of mention') = Year(Today())
     ),
     'Date of mention',
     SortOrder.Descending
    
     )
    );
    
    ClearCollect(
     SortedMonth2,
     Sort(
     Filter(
     FilteredRecords,
     Month('Date of mention') = Month(DateAdd(Today(), -1, Months)) 
     && Year('Date of mention') = Year(DateAdd(Today(), -1, Months))
     ),
     'Date of mention',
     SortOrder.Descending
     )
    );
    

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 339 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 289

#3
Mohsin Ali Profile Picture

Mohsin Ali 228

Last 30 days Overall leaderboard