Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set Analysis Syntax for comparing two date fields as a OR statement not working

I would like to perform the following simple SQL or condition within  Qlik:

SELECT Count(1)

FROM  FactTable

WHERE  (SaleDate BETWEEN 20160501  AND 20160531

OR    [QuoteDate] BETWEEN 20160501 AND 20160531)


i.e simple or condition. I am using the inbuilt calendar liked to SaleDate so this calls for set Analysis.  However I am missing a couple of records due to the "or" statement failing:

RowNoQuoteDateSaleDate
12016043020160507
22016051320160609
32016052720160621

If I base it upon my logic on the Quote date (equal to MAY 2016) I miss the first row which should be included as the sale date is in MAY. If I base my logic on the Sale date I miss rows 2 and 3 which  should be included as the quote took place in MAY hence the OR.

What I have in Qlikview is:

=Count ({$< YearMonth =  {"$(=Date(QuoteDate,'YYYY-MM'))"},Year=,FiscalYear=,Month=,WeekDay=,Quarter= > +
<
YearMonth =  {"$(=Date(SaleDate,'YYYY-MM' ))"},Year=,FiscalYear=,Month=,WeekDay=,Quarter=>} IsSale

YearMonth is  2016-05 created from the selected year and month. No other date selections are made or available. By the way I have converted the dates to proper dates in the loads script. Sumof ISsale are Sales, Count of IsSale are quotes.

Simply stated  what I want is to include all quotes where the QuoteDate OR the saleDate match the selected (YearMonth e.g. ‘2016-05’) ignoring all date related sections so I am left with the full set of date related data to make the comparison .

Many Thanks in Advance & Kind Regards

Mike

12 Replies
mjtaft2017
Partner - Creator
Partner - Creator

Ruben -

I don't understand what the -*  is for on the end of a couple of the statements just before the }

=Count({<QuoteDate={"$(=Date(Max(SaleDate),'YYYY-MM'))-*"},

SaleFiscalYear=,SaleWeekDay=,SaleQuarter=, SaleMonth= >  +

         <SaleDate={"$(=Date(Max(SaleDate),'YYYY-MM'))-*"}, SaleFiscalYear=,SaleWeekDay=,SaleQuarter=, SaleMonth= >} IsSale)

Can you explain what that is doing?

rubenmarin

Hi Mary, that's the string used to search, and the '*' is a wildcard to look for all combitanion of characters, ie: using "2018-10-*", filters dates starting by '2018-10-', wich will be all dates for october 2018.

https://help.qlik.com/en-US/qlikview/November2017/Subsystems/Client/Content/Text_search_and_numeric_...

viradia123
Contributor
Contributor

I am comparing this way. Am I doing wrong?

Count({<[FIELD_NAME_1] = {'VALUE1'}, [DATE_FILED_1] -= {'[DATE_FILED_1] <= [DATE_FILED_12])'}>} COUNT_FIElD_NAME)