QueryBuilder API in CQ5 - query on the basis of date range - search

I need to search on the basis of "Last month", "Last week", "Last 3 months", "Last year"..
Am using the code as below.
map.put("1_relativedaterange.property", "date");
map.put("1_relativedaterange.lowerBound", "-1M");
Respectively putting -7d, -3M, -1y.
These work for last date ranges. I expect that with these criteria it should not search if the dates are next month, next week or next year. But it is searching that as well, which should not.
Anybody please point out what I am doing wrong here?
Thanks.

When you specfify the lowerBound, the resulting Xpath query that is generated is
/jcr:root/content/geometrixx/en//element(*, cq:Page)
[
(#jcr:content/cq:lastModified > xs:dateTime('2014-05-30T02:18:50.479Z'))
]
which means it would fetch all the items which has date value greater than the above.
You can specify an upperBound value as 0, indicating now. This would return only those results that do not exceed the current date, apart from satisfying your other criteria.
map.put("1_relativedaterange.property", "date");
map.put("1_relativedaterange.lowerBound", "-1M");
map.put("1_relativedaterange.upperBound", "0");
and the corresponding XPath query that gets generated is
/jcr:root/content/geometrixx/en//element(*, cq:Page)
[
(#jcr:content/cq:lastModified > xs:dateTime('2014-05-30T02:25:21.026Z')
and #jcr:content/cq:lastModified < xs:dateTime('2014-06-29T02:25:21.026Z'))
]
The querydebug console(/libs/cq/search/content/querydebug.html) might come in handy when you need to debug your queries.
For additional info on relative date range predicate evaluator, refer the docs.

Related

Filter between 2 dates using a date from another transction

I have a custom record that has 3 fields:
Sequence Number
Start Date
End Date
What I am trying to do is create a search via suitescript that takes a date from an invoice (the date is in a custom field) and find the sequence number that falls within the start date and end date.
I tried using the below filters (myDate = the date from the invoice field which in my example is 9/26/2022) but this did not turn up any results even though there is a custom record with a start date of 9/25/2022 and an end date of 10/1/2022:
filters:
[
["custrecord_startDate","onorafter",myDate],
"AND",
["custrecord_endDate","onorbefore",myDate]
]
What would be the best way to filter my results to get the correct value?
From what you've written try substituting the dates:
filters:
[
["9/25/2022","onorafter","9/26/2022"],
"AND",
["10/1/2022","onorbefore","9/26/2022"]
]
If that's correct then you have the logic backward
If you want to find the custom records whose start and end bracket the transaction date you need:
["custrecord_startDate","onorbefore",myDate],
"AND",
["custrecord_endDate","notbefore",myDate]
]
Note the notbefore for the end date. This covers the case where the custom record starts but is open-ended. If the end date is never empty, then onorafter is the operator to use.

Index Match to return MAX Date with multiple criteria

apologies for this, I'm assuming this is simple but a few hours of SO googling hasn't helped
Enough whining from me:
Consider the following dataset:
ID, Date, Review, Review Status
1 01/02/18, "Cool", Positive
1 01/03/18, "Awesome", " Positive
1 01/01/18, "Cumbersome", Negative
1 01/02/18, "Rubbish!", " Negative
I'm currently using an array type index match to get the latest review based on a few conditions
I have two columns one which says positive, one negative.
in each of the column I would like to return the latest positive review but I'm unsure how to get the max date within the below formula:
{=index(C2:C4, MATCH(1,(1 = A2:A4)*("Positive" = D2:D4)*(maxdatehere = B2:B4),0))}
The data I have is around 7k rows and is Google Review Data and pretty much matches the example above.
I'd rather not use VBA as I've never really used it before (but will do so grudgingly)
as this is excel I've not created a google demo sheet, but happy to do so for ease of the experts and for others to benfit if they find there way here one day.
If you have Office 365:
=INDEX(C2:C5, MATCH(1,(1 = A2:A5)*("Positive" = D2:D5)*(MAXIFS(B:B,A:A,1,D:D,"Positive") = B2:B5),0))
Confirme with Ctrl-Shift-enter instead of Enter when exiting edit mode.
If you have 2010 or later then:
=INDEX(C:C,AGGREGATE(15,7,ROW(C2:C5)/((A2:A5=1)*(D2:D5="Positive")*(AGGREGATE(14,7,B2:B5/((A2:A5=1)*(D2:D5="Positive")),1)=B2:B5)),1))
Entered normally.

Date status function to displays Overdue, Due Later and Due Soon

I am currently working on function in Excel that will display the status of an activity based on the due date provided.
This function would display:
"Overdue" if Today()> Due Date;
"Due Soon" If the Due date was within one week
"Due Later" if Today() < Due Date +7
Below is an example of what I was able to muster up:
Function Status_of_Date()
If Sheets("Issue_Log").Range("Due_Date").Value < Date Then
Sheets("Issue_Log").Range("Date_Status").Value = "Overdue" 'overdue
ElseIf Sheets("Issue_Log").Range("Due_Date").Value < 7 + Date Then
Sheets("Issue_Log").Range("Date_Status").Value = "Due Later" ' Due Soon
ElseIf Sheets("Issue_Log").Range("Due_Date").Value > 7 + Date Then
Sheets("Issue_Log").Range("Date_Status").Value = "Due Later" ' Due Later
Else
End If
End Function
Codeless Solution
Add a column to your table, to count the days left - since anything negative is overdue anyway, make all negatives -1:
Use a table formula to calculate it:
=IF([#[Due Date]]-TODAY()<0,-1,[#[Due Date]]-TODAY())
Next, have another table to hold the status given a number of days:
Since you have 3 statuses, and they're really ranges of values, to achieve the values you're after you'll need:
A row with -1 for everything Overdue
A row with 0 for everything due Soon
A row with 7 for everything due Later
Now your "Date Status" column can be a simple VLOOKUP formula:
Again, a table formula is used; note the "approximate match" last parameter:
=VLOOKUP([#Days],tblStatusLookup,2,TRUE)
Adjust tblStatusLookup to whatever you've named your lookup table.
Look 'ma, not a single line of code!
Then you can hide the [Days] column if you don't need it shown, and the lookup table can be anywhere you want - and if the thresholds need to change, or if new statuses need to be added, you just tweak the lookup table (important: keep the [Days] sorted ascending, that's how approximate match VLOOKUP works!)
Bugs in OP
Your function needs to know what row to work with. That should be a parameter; change the signature to accept one - or even better, change it to accept a DueDate parameter - then you simply don't need to care about anything other than the date you're given:
Public Function GetDateStatus(ByVal dueDate As Date) As String
If dueDate - Date < 0 Then
GetDateStatus = "Overdue"
ElseIf dueDate - Date < 7 Then
GetDateStatus = "Due Soon"
Else
GetDateStatus = "Due Later"
End If
End function
And then in your table the formula would be:
=GetDateStatus(#[Due Date])
No need to be bothered with ranges and the nitty-gritty details of how and where every value is coming from - code gets much, much simpler when you work at the right abstraction level!
Note that a worksheet function is not allowed to change other cells' values: it calculates a value.

Rounding Summarized Saved Search Results

I created a saved search on sales orders to calculate days between order date and ship date, grouped and averaged by class (the formula is cased to distinguish between 'Wholesale' class and all others). The numeric formula is:
CASE WHEN {class} = 'Wholesale' THEN {actualshipdate} - {startdate} ELSE {actualshipdate} - {shipdate} END
The summary type for the formula result is average. The summary-level results have way too many decimal places. Is there a way to round the summarized results to a pre-defined number of digits?
I have tried using the ROUND() function, both inside the CASE statement and as a wrap-around. I've also looked through general preferences for rounding defaults and haven't found any.
In order to round the result, you should implement you own average calculation and rounding.
Add the following result field besides the class grouping field that you already have:
Field : Formula (Numeric)
Summary Type : Maximum
Formula : ROUND(SUM(CASE WHEN {class} = 'Wholesale' THEN {actualshipdate} - {startdate} ELSE {actualshipdate} - {shipdate} END) / COUNT({internalid})),2)
Basically, you are doing here your own analytics.
Since the results are grouped, each result fields contains the whole result set of this field which allows you to add analytical functions on this group.
The summary type is MAXIMUM, just in order to show one result, so it can also be min or avg, no difference.
The function is calculating the sum of your formula and dividing it by the records count to get the average.

Sharepoint CAML Date query

im getting different results based on the date i use to search on.
Here are the 3 records i want to display, their values for EVENTDATE, and ENDDATE are as follows
1, 2009-08-11T00:00:00Z, 2009-08-14T23:59:59Z
2, 2009-08-11T00:00:00Z, 2009-08-14T23:59:59Z
3, 2009-08-14T20:00:00Z, 2009-08-14T22:00:00Z
When i search for a time between EventDate and EndDate
- 2009-08-14T20:00:00Z, 2009-08-14T22:00:00Z
= i get rows 1,2
- 2009-08-14 T20:00:00Z, 2009-08-14 T22:00:00Z
= i get rows 3
Why does adding a space between the date and time give me a diff result? The entries into the list are the same, the return results dates are the exact same format.
Although the ISO 8601 standard specifies that a space to either side of the T is valid, I would guess that the CAML parser only accepts non spaces. And what you are seeing is a side effect.

Resources