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.
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"
)
)
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
)
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")
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.
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
Yes comma is a typo. Doesn't work regardless of the comma.
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")
WarrenBelz
791
Most Valuable Professional
MS.Ragavendar
410
mmbr1606
275
Super User 2025 Season 1