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 / Using an If statement ...
Power Apps
Answered

Using an If statement inside a ClearCollect Filter

(0) ShareShare
ReportReport
Posted on by 35

Hi

 

I have a PowerApp which has multiple SP lists as data sources. One of the SP lists is considered the main list, and the other is considered the 'child' list.

In a Gallery on one of the app screens, I need to only show records from the main list where there is at least one item with the same ID in the child list, and in addition the filter should restrict to child list items where the 'Month' value is the current month, and where the 'Year' value is the current financial year. 

Here is a sample of the child SP list dataset:

 

tomburton2023_0-1704447528972.png

 

 

I have set up a ClearCollect in the OnVisible screen property with the following code:

 

ClearCollect(MonthValues2,Filter('Corporate WIP System - Month values',Month in Text(Today(),"mmmm"),

If("January" exactin Text(Today(),"mmmm") Or "February" exactin Text(Today(),"mmmm") Or "March" exactin Text(Today(),"mmmm"),
EndsWith(Year,Right(Today(),4)),
StartsWith(Year,Right(Today(),4)))))

 

The logic behind the filter above is that if the current month is January, February or March, only items where the current year (ie today) is at the end of the 'Year' value of the child list item (eg '2023-2024') are included, whereas if the current month is April onwards, items where the current year is at the start of the 'Year' value are included.

 

I then pass the output of this ClearCollect into the gallery's Items property. It is not working as expected.

 

Any help or advice appreciated. I'm wondering if embedding an If statement into the Filter in this way is the issue, and whether conceptually there is a different/better way of achieving this.

 

Thanks, Tom

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

    Hi @tomburton2023 ,

    I think I have the logic right here

    With(
     {
     _End: Text(Today(),"mmmm") in ["January", "February", "March"],
     _Year: Year(Today())
     },
     ClearCollect(
     MonthValues2,
     Filter(
     'Corporate WIP System - Month values',
     (
     _End && 
     EndsWith(_Year)
     ) ||
     (
     !_End && 
     StartsWith(_Year)
     )
     )
     )
    )

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • tomburton2023 Profile Picture
    35 on at

    Hi @WarrenBelz 

    Thanks very much for your help - that has worked well 🙂

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

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard