Skip to main content
Announcements
See why Qlik was named a Leader in the 2024 Gartner® Magic Quadrant™ for Data Integration Tools for the ninth year in a row: Get the report
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Qlik Sense Default to a date not working

I have a statement that i can never get to work with a date field.  It is below:

Count({$<[BusinessDate]= {'$(=If(GetSelectedCount([BusinessDate]) < 1, Max([BusinessDate]), [BusinessDate]))'}>} MemberNbr)

I am trying to get a count of MemberNbrs for the month and set the max BusinessDate as the default if there are no selections made.  If i make a selection then i get the results i would expect.  If i select the max date on a chart then i get the count i want,  but if there is no selection then my KPI shows 0.

It works fine if the BusinessDate is a text field.  However when the BusinessDate is a date field then the KPI returns 0.  Any ideas what i am doing wrong?



1 Solution

Accepted Solutions
sunny_talwar

Try this script:

Table:

LOAD

    MembershipMonthlySKey,

    Date(MonthStart(Date#(MonthID, 'YYYYMM')), 'YYYYMM') as MonthID,

    Date(BusinessDate) as BusinessDate

FROM [lib://Lib/TestData.xlsx]

(ooxml, embedded labels, table is Sheet1);

and these two expressions should work for you

Count({$<[MonthID]= {"$(=Date(Max([MonthID]), 'YYYYMM'))"}>} MonthID)

Count({$<BusinessDate= {"$(=Date(Max(BusinessDate)))"}>} MonthID)

Capture.PNG

View solution in original post

18 Replies
sunny_talwar

Have you tried this:

Count({$<[BusinessDate]= {"$(=Max([BusinessDate]))"}>} MemberNbr)

or this

Count({$<[BusinessDate]= {"$(=Date(Max([BusinessDate]), 'DateFieldFormatHere'))"}>} MemberNbr)


Not applicable
Author

so what i am really trying to do is get the previous months count, I tired

Count({$<[BusinessDate]= {"$(=addmonths(Max([BusinessDate])),-1)"}>} MemberNbr)

sunny_talwar

May be something like this:

Count({$<[BusinessDate]= {"$(=AddMonths(Max([BusinessDate])),-1))"}>} MemberNbr)

or

Count({$<[BusinessDate]= {"$(=Date(AddMonths(Max([BusinessDate])),-1), 'DateFieldFormatHere'))"}>} MemberNbr)

Not applicable
Author

Thanks for the response but neither of those are working either, i still cant figure out why.

Not applicable
Author

For example this code works just fine:

Count({$<[MonthID]= {$(=If(GetSelectedCount([MonthID]) = 0, max([MonthID]), [MonthID]))}>} MemberNbr)

MonthID is a character field that says '201601' as an example.  This works.

But when i use the same code as and the field is a date then it doesnt work:

Count({$<[MDate]= {$(=If(GetSelectedCount([MDate]) = 0, max([MDate]), [MDate]))}>} MemberNbr)

where Mdate is a date field.

sunny_talwar

What is your MDate format? DD/MM/YYYY or MM/DD/YYYY or something else?

Not applicable
Author

Mdate is YYYY-MM-DD

sunny_talwar

Have you already tried this?

Count({$<[MDate]= {$(=Date(Max([MDate]), 'YYYY-MM-DD'))}>} MemberNbr)

This should be a helpful link to read Dates in Set Analysis

If for some reason this doesn't work, then the next thing you need to check is that if MDate is a dual field with numeric value or not. For that you can see these blogs

Why don’t my dates work?

QlikView Date fields

Get the Dates Right

Not applicable
Author

I tried the one above with no luck, thanks again, i will check out these articles and post the result if i can figure it out.