Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Count in Canonical Date doesn't give correct values

Hi guys,

I feel more and more comfortable with Qlik Sense but some parts are still confusing. For example, today I got the canonical dates working...Well...halfway.

There is a vessel table which has 39,691 records; gate table with 60,214 records and moves with 71,765 records. The concatenated DateLink table has 171,670 records.

But then, if I use =count({<Flag={'Date_gate'}, Flag2={'Container_Gates'}>} Container) or

=count({<Flag={'Date_moves'}, Flag2={'Container_Moves'}>} Container) and select a day using the date from the filter panel '=Date(Floor(Date(TimeStamp,'MM/DD/YYYY hh:mm:ss.ffff')),'DD/MM/YYYY')'

I am not getting the correct values. They are usually higher than they should be. If I don't select any date, the count gives lower values than it should be i.e. Count using  Container_Moves, Container_Vessel and Container_Gate.

What am I doing wrong in my query?

Background: the vessel table contains information on the vessel visit i.e. one vessel visit could have many containers (container id) but one departure date (EST_DPTR_D).

The move table contains information on the container moves where [TET] is the hour of the move.

The gate table contains information on the time ([TRACTOR_DEPART_DATE]) a container left the port.

The requirement is to have one calendar on the front-end which will allow a user to pick a date and see the # of containers which were moved within the port (move table) and left the port (gate table). In theory, the number of moves in the vessel table should match with the number of moves in the moves table, so I use both tables interchangeable. For this reason, I named all three fields i.e. TET, EST_DPRT_D and TRACTOR_DEPART_DATE as TimeStamp. It was all good but I need to do some calculation which requires usage of columns from the vessel table and move table.

So, I looked into the canonical date feature. It looks good i.e. I can perform calculation using cols from both tables, but now I have an issue of bizzare count.

Vessel:

LOAD

[idvessl],

    `EST_DPTR_D` ,

    `CNTR_NUM` as Container

FROM [lib://Desktop/vesel_load.xlsx]

(ooxml, embedded labels, table is Sheet1);


Moves:

LOAD

[idmove],

[CONTAINER] as Container,

[TET]

FROM [lib://Desktop/move_vessel_upload.xlsx]

(ooxml, embedded labels, table is Sheet1);


Gate:

LOAD

[idgate],

[CNTR] as Container,

[TRACTOR_DEPART_DATE]

FROM [lib://Desktop/gate_10.xlsx]

(ooxml, embedded labels, table is Sheet1);


DateLink:

LOAD

Container

,'Container_Moves' as Flag2 

,Timestamp([TET],'DD/MM/YYYY hh:mm:ss tt') as TimeStamp   

  ,'Date_moves' as Flag  

RESIDENT Moves

;

Concatenate

LOAD

Container

,'Container_Gates' as Flag2

,Timestamp([TRACTOR_DEPART_DATE],'DD/MM/YYYY hh:mm:ss tt') as TimeStamp

,'Date_gate'  as Flag   

RESIDENT Gate

;

Concatenate

LOAD

Container

    ,'Container_Vessels' as Flag2

,Timestamp(`EST_DPTR_D`,'DD/MM/YYYY hh:mm:ss tt') as TimeStamp       

,'Date_vessel'  as Flag   

RESIDENT Vessel

;





//Creating a calendar

SUB CalendarFromField(_field, _calendar, _prefix)

[$(_calendar)]:


LOAD

Date(Floor(Date([$(_field)],'MM/DD/YYYY hh:mm:ss.ffff')),'DD/MM/YYYY') AS [$(_prefix)Date],

[$(_field)]

,year([$(_field)]) as [$(_prefix)Year]

,month([$(_field)]) as [$(_prefix)Month]

,day([$(_field)]) as [$(_prefix)Day]

,weekday([$(_field)]) as [$(_prefix)Weekday]

    ,hour([$(_field)]) as [$(_prefix)Hour]

    ,minute([$(_field)]) as [$(_prefix)Minute]   

;


LOAD

date(DateMin + IterNo()) as [$(_field)]

WHILE DateMin + IterNo() <= DateMax

;


LOAD

min(datefield)-1 as DateMin

,max(datefield) as DateMax

;


LOAD

FieldValue('$(_field)', RecNo()) as datefield

AutoGenerate FieldValueCount('$(_field)');


END SUB


CALL CalendarFromField('TimeStamp', 'CommonCalendar', '');

28 Replies
swuehl
MVP
MVP

The Dayname() is just creating a real date from your timestamp, truncating the time value off and formatting as date.

Not sure what you want or need, but take care to

Get the Dates Right

see also

Why don’t my dates work?

robert99
Specialist III
Specialist III

Dayname cuts off the seconds

You can either use dayname or date(floor(   ----- ))

As I understand things you must use a date not timestamp to link to a calendar (a date to a date)

If you want a timestamp just do something like this in the tables

date(floor(`EST_DPTR_D)) as CanonDate ,  (join to linktable)

`EST_DPTR_D as `EST_DPTR_D_Timestamp

etc

robert99
Specialist III
Specialist III

Hi Stefan

You are more of a expert than me (by far)

In the example above would you join these 3 tables by container or concatenate them. I would likely concatenate them anyway without the canonical date issue.

robert99
Specialist III
Specialist III

,Dayname([TRACTOR_DEPART_DATE]) as TimeStamp 


Its not a  timestamp now. Its a date

Anonymous
Not applicable
Author

Thank you for the reply, Robert. If I understood correctly, you suggest me to preserve the timestamp format in the main tables. Why do I need to have time? (1) Along with the calendar (date range picker extension), I also added the date filter panel where a person can type, e.g. >=1/1/2018 06:00:00 AM<=2/1/2018 05:59:59 AM in order to see what the performance for three shifts was; (2) I created time intervals i.e. 06-14, 14-22, 22-06 to report on the shift performance in the form of a graph/table.

To put it another way, with the date picker one could get the calendar data, but some metrics are tracked on a shift basis i.e. from 6am to 6am. So I guess I need to have the timestamp in the LinkTable.

Yeah, I figured that it's a date )

Anonymous
Not applicable
Author

Yeah, I figured it ) See my question above.

robert99
Specialist III
Specialist III

Based on this I would Concatenate the three tables

Have columns like this

TableType (to distinguish between the table type)

A date field  (linked to calendar of Year, Month, Day week etc)

an hours field

Shift field one (hours between whatever

Shift field two etc (hours between whatever

So then a person can

select a Month, Year, Day , hour range  and or shift field etc

Or you can filter by these fields in a chart or table

You will only need a canonical date if you have two times in the same table that you want a linked calendar for

I have even in one job concatenated one table twice. To get two time stamps lined up I used a field (TableType) to distinguish between the table type

'Gate1' as TableType (1st concatenation)

'Gate2' as TableType  (2nd concatenation)

I guess maybe you could have a time only and link to a Time calendar. Rather than including it in the concatenated tables. But if you only want hours there is no really need

edit You can (I think) link a Timestamp to a timestamp in a Timestamp  calendar (inc Hours, Minutes day Monthyear etc). But not a timestamp to a date. But it might slow QLIK down

Anonymous
Not applicable
Author

Thank you for the response, Robert!

Let me test yours and Stefan's version tomorrow! I call it a day!

Night!

robert99
Specialist III
Specialist III

Let us know what solution you used