Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
dwfiv327
Contributor II
Contributor II

Computing Age across tables

I have two tables, one with personal information, like data of birth.  And another table with transaction date.  They can be joined via a Cust_ID.  Is there a way, during the load process to computer the difference in these two dates for a customer for all of her or his corresponding transactions? 

In other words, I want the age of a person at the time of the transaction, but the two dates are in different tables and doing the age calculation at the time of displaying the chart is unacceptably slow.

Any help would be greatly appreciated.

-Daniel

5 Replies
m_woolf
Master II
Master II

If you join load the two tables, you will get a single table. Then you can calculate the date differences.

dwfiv327
Contributor II
Contributor II
Author

Didn’t work. Here is a snippet of my code. What it gets to the line with ContactAge, I get an error message about not finding birthday.

LOAD CustomerID,

Birthday,

age(today(),Birthday) as CustAge,

Year(Birthday) as BirthYear,

date(Birthday) as dob,

IDType2;

SQL SELECT *

FROM PersonalInfo;

Inner Join

LOAD SessionID,

CustomerID,

date(SessionDate) as SessDate,

age(SessionDate, Birthday) as ContactAge,

Reason;

SQL SELECT *

FROM Session;

Daniel W. Farrow, IV

DISCLAIMER: This e-mail and any files transmitted with it may contain confidential and/or proprietary information. It is intended solely for the use of the individual or entity who is the intended recipient. Unauthorized use of this information is prohibited. If you have received this in error, please contact the sender by replying to this message and delete this material from any system it may be on.

m_woolf
Master II
Master II

Try just joining the 2 tables.

Look at the resulting single table. I suspect that you can't calculate the age until after the tables are joined.

MarcoWedel

Hi,

one solution could be:

QlikCommunity_Thread_206869_Pic1.JPG

QlikCommunity_Thread_206869_Pic2.JPG

tabPersonalInfo:

LOAD RecNo() as CustomerID,

     Date(MakeDate(1950)+Ceil(10000*Rand())) as Birthday

AutoGenerate 10;

tabSession:

LOAD RecNo() as SessionID,

     Ceil(Rand()*10) as CustomerID,

     Date(Today()-Ceil(Rand()*5000)) as SessionDate

AutoGenerate 50;

Left Join (tabSession)

LOAD CustomerID,

     Birthday

Resident tabPersonalInfo;

Left Join (tabSession)

LOAD Distinct

     Birthday,

     SessionDate,

     Age(SessionDate,Birthday) as ContactAge

Resident tabSession;

DROP Field Birthday From tabSession;

hope this helps

regards

Marco

MarcoWedel

another possible solution might be:

tabPersonalInfo:

LOAD RecNo() as CustomerID,

    Date(MakeDate(1950)+Ceil(10000*Rand())) as Birthday

AutoGenerate 10;

mapPersBirthday:

Mapping LOAD * Resident tabPersonalInfo;

tabSession:

LOAD *,

    Age(SessionDate,ApplyMap('mapPersBirthday',CustomerID)) as ContactAge;

LOAD RecNo() as SessionID,

    Ceil(Rand()*10) as CustomerID,

    Date(Today()-Ceil(Rand()*5000)) as SessionDate

AutoGenerate 50;

hope this helps

regards

Marco