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 / Gallery filtered by Da...
Power Apps
Unanswered

Gallery filtered by Datediff in if statement

(0) ShareShare
ReportReport
Posted on by 638

Hello,

 

I'm trying to filter a gallery based on the datediff within an if statement to establish a threshold of DateDiff numbers such as <=1,<=14, >14

 

Search(
 Filter('Risk Mitigations',
 Status = Statuses &&
 Department.Value = Viewgr.Value && DateDiff(Today(),'Target Closure Date') <= 14,)
 
 
 ,
 TextSearchBox1_11.Text,"MitigationDescription","Title")

 

Really stuck on this, any help appreciated.

Categories:
I have the same question (0)
  • Akser Profile Picture
    1,546 Moderator on at

    Hi @jbrit2020,

     

    Is there an extra comma there?

    Search(
     Filter('Risk Mitigations',
     Status = Statuses &&
     Department.Value = Viewgr.Value && DateDiff(Today(),'Target Closure Date') <= 14,) //The comma after 14 must be a typo?
     
     
     ,
     TextSearchBox1_11.Text,"MitigationDescription","Title")
  • jbrit2020 Profile Picture
    638 on at

    Yes comma is a typo. Doesn't work regardless of the comma.

  • Akser Profile Picture
    1,546 Moderator on at

    Not sure if the error is related to your DateDiff formula as it looks OK. The Department check looks good too (I guess choice field in SharePoint?). Can you help me understand the type of Status and Statuses?

    Filter('Risk Mitigations',
     Status = Statuses

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @jbrit2020 

    You mention an If() function but don't show one in the formula you posted.  Is there more to it? Could you post a screenshot showing the full formula and error message. 

  • jbrit2020 Profile Picture
    638 on at

    It's sorted, I was being an idiot. Do you reckon there's a more elegant way to go about it though?

     

    Search(
     Filter('Risk Mitigations',
     Status = Statuses &&
     Department.Value = Viewgr.Value && If(Ragsy = "Green", DateDiff(Today(),'Target Closure Date') > 14,If(Ragsy = "Amber", DateDiff(Today(),'Target Closure Date') >1 &&DateDiff(Today(),'Target Closure Date') <15,DateDiff(Today(),'Target Closure Date') <2)))
     
     
     ,
     TextSearchBox1_11.Text,"MitigationDescription","Title")
  • Akser Profile Picture
    1,546 Moderator on at

    Maybe a small change can be made to make it easier to read?

    If(Ragsy = "Green", DateDiff(Today(),'Target Closure Date') > 14,If(Ragsy = "Amber", DateDiff(Today(),'Target Closure Date') >1 &&DateDiff(Today(),'Target Closure Date') <15,DateDiff(Today(),'Target Closure Date') <2))
    
    //Becomes
    Switch
    	(
    	Ragsy, 
    	"Green",
    	DateDiff(Today(),'Target Closure Date') > 14,
    	"Amber",
    	DateDiff(Today(),'Target Closure Date') >1 &&DateDiff(Today(),'Target Closure Date') <15,
    	DateDiff(Today(),'Target Closure Date') <2
    	)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @jbrit2020 

    I think this is a bit more elegant:

     

    With({fltrd:Filter('Risk Mitigations',Status = Statuses, Department.Value = Viewgr.Value),
     dd: DateDiff(Today(),'Target Closure Date')
     }, 
     Search(
     Switch(Ragsy, "Green",Filter(fltrd, dd > 14),
     "Amber", Filter(fltrd, dd > 1),
     "someothercolor"= Filter(fltrd,dd < 15), //looks like you left one out
     Filter(fltrd,dd < 2
     ), TextSearchBox1_11.Text,"MitigationDescription","Title"
     )
    )

     

     

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 483

#2
WarrenBelz Profile Picture

WarrenBelz 399 Most Valuable Professional

#3
11manish Profile Picture

11manish 327

Last 30 days Overall leaderboard