Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count of a field based on two dates

Hi All,

I am using a chart to display the count of some records. I have a condition where I need to display the sum of records if one date = another.

Consider this example.

   

NameDate1Date2
A4/10/20154/10/2015
B4/10/20154/10/2015
C4/10/20154/11/2015
D4/11/20154/12/2015
E4/11/20154/12/2015

I need the output as

  

DateCount
4/10/20152
4/11/20150
4/12/20150

Count of 2 includes records A and B because Date1=Date2. And 0 for the other records.

Could you please advise how this can be done?

Thanks in advance.

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

If both the fields are in the same table then you can do it in script easily like below

Data:

Load

Name,

Date1,

Date2,

If(Date1=Date2,1, 0) As DateFlag

From DataSource;

Now in front end you can use

Dimension: Date1

Expression: Sum(DateFlag)

If both the fields are in different tables then try like below

Dimension: Date1

Expression: Sum(Aggr(If(Date1= Date2, 1, 0), Date1, Date2))

Hope this helps you.

Regards,

Jagan.

View solution in original post

6 Replies
Not applicable
Author

Hi Varun,

I would do this comparison in the script to create a flag, which you can then easily use within set analysis.

Load

Name,

Date1,

Date2,

If(Date1=Date2,1) As MatchedDateFlag

From.....

Then in your expression simply

Count( {<MatchedDateFlag={1}>} Date1)

hope that helps

Joe

sushil353
Master II
Master II

Hi,

Please try below code:

Test:
LOAD *,if(Date1=Date2,'1','0') as flag Inline
[
Name,Date1,Date2
A,4/10/2015,4/10/2015
B,4/10/2015,4/10/2015
C,4/10/2015,4/11/2015
D,4/11/2015,4/12/2015
E,4/11/2015,4/12/2015
]
;

Table2:
LOAD sum(flag) as count,
Date2 as Date
Resident Test
Group by Date2;

HTH

Sushil

Anonymous
Not applicable
Author

Hi,

PFA

Thanks

BKC

jagan
Luminary Alumni
Luminary Alumni

Hi,

If both the fields are in the same table then you can do it in script easily like below

Data:

Load

Name,

Date1,

Date2,

If(Date1=Date2,1, 0) As DateFlag

From DataSource;

Now in front end you can use

Dimension: Date1

Expression: Sum(DateFlag)

If both the fields are in different tables then try like below

Dimension: Date1

Expression: Sum(Aggr(If(Date1= Date2, 1, 0), Date1, Date2))

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

Hi Joe,

The two fields are from different tables and hence I did not use this method. I used Jagan's method and the results were accurate.

Thanks for your quick response. Really appreciate it.

Not applicable
Author

Hi Jagan,

This method worked fine. The fields were indeed from two different tables.

Thanks for the quick response.