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

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
pra_kale
Creator III
Creator III

How to bifurcate data on the basis of Date

Hi,

I have created one sample data module which consist of 4 tables as given below.

1) Premium

2) Overall...Fact Table

3) Issuance

4) Product_UIN

In product_UIN table i have product codes and UIN and their launch dates. In summary table i want to bifurcate data on the basis of product launch date. For e.g. In case of Product code FCD i want data on or before  13-09-2015 should reflect under UINNo ACDVI1 and after 13-09-2015 should reflect under UINNo ACDVI2.


Final out-put is given below..

    

Product_CodeUINPolicy_CountPremium Total
ABCABVIP1382000
ABCABVIP24122000
DEFDEXDI218000
FCDACDVI1393000
FCDACDVI2237000
JKLJKLVD213000
UAXUAXDI13577000
UAXUAXDI21195000
UINABCDV1239000
Grand Total 201156000


Please guide how i will get the final out-put.

Thanks in advance.

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Ok, try joining the intervalmatch table with the Overall table.

LEFT JOIN (Overall)

IntervalMatch(Issuance_Date, ProductCode)

LOAD

      Start_DT, END_DT,ProductCode

RESIDENT

     Product_UIN;

You'll still have one synthetic key left after that, but that's not a problem. If you want to get rid of that one as well you can next left join the Product_UIN table to the Overall table and then drop the Product_UIN table.


talk is cheap, supply exceeds demand

View solution in original post

8 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Your document contains these records for FCD:

ProductCode UINNo launchDate
FCDACDVI113-09-2015
FCDACDVI214-09-2015

It makes no sense to me if you want for ACDVI1 the policy numbers that lie before the launchDate and for ACDVI2 those on or after the launchDate. 13-09-2015 is obviously not a launch date. Suppose your table contains these records:

ProductCode UINNo launchDate
FCDACDVI113-09-2015
FCDACDVI214-09-2015
FCDACDVI301-01-2016
FCDACDVI402-01-2016

Now which policies belong to which UINNo?

I think you should first create a clean Product_UIN table that contains the real launch dates. Otherwise it's next to impossible to correctly 'bifurcate data'


talk is cheap, supply exceeds demand
pra_kale
Creator III
Creator III
Author

Hi,

I agree with you Gysbert. Column name which i have given in the file is confusing because i have kept launch date for both the UIN.

Now i have change the column name and kept launchDate/EndDate.

Actually the thing is, dates mentioned in front of product codes FCD and UINNo ACDVI1 , UAX and UAXDI1, ABC and ABVIP1 are UIN End Dates where as product codes FCD and UINNo ACDVI2 , UAX and UAXDI2, ABC and ABVIP2 are having UIN Starts Dates. It means the policies issued on or before 13-09-2015 in case of FCD products should bifurcated under UIN ACDVI1 and policies issued after 14-09-2015 should carry UIN ACDVI2. same thing hold goods for other products as well.

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

That's great.

Actually just renaming the field doesn't help at all. The data sucks regardless of the name of the field. It takes a human to figure out what should be done. A computer can't make such guesses correctly. What your table should look like is something like this:

  

ProductCodeUINNolaunchDateEndDate
UINABCDV11/1/1900
FCDACDVI11/1/19009/14/2015
FCDACDVI29/14/2015
UAXUAXDI11/1/190010/13/2015
UAXUAXDI210/13/2015
DEFDEXDI21/1/1900
GHIGHIJD11/1/1900
JKLJKLVD21/1/1900
ABCABVIP11/1/19005/6/2015
ABCABVIP25/6/2015

Then you can calculate intervals in which the UINNo's are valid and match the dates of the policies with the intervals using the IntervalMatch function.


talk is cheap, supply exceeds demand
pra_kale
Creator III
Creator III
Author

Hi,

Thank you very much Gysbert. You are really great..!!!

What you have mentioned is absolutely true. I have to modify the product file the way you did.

As I  so far never used Intervalmatch function. Can you please help how i should use in above case. As my Issuance data and Premium data is coming from 2 different files where as my main file contains Product and their dates.

Can you please help how is to be done..

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

First read this document: IntervalMatch and Slowly Changing Dimensions

Note, you have intervals for each ProductCode. That means you need to use ProductCode as key in the intervalmatch function so the issuedates will be matched with the intervals that have the same ProductCode as the policy has:

IntervalMatchTable:

IntervalMatch(IssueDate, ProductCode)

LOAD

     launchDate, EndDate ProductCode

RESIDENT

     ProductVersion;

There's one more thing you need to take into account. If a record doesn't have an EndDate value then you need to create one first. Otherwise the intervalmatch function doesn't find an interval. You can replace a missing EndDate with for example today's date: Alt(EndDate, Today()) as EndDate


talk is cheap, supply exceeds demand
pra_kale
Creator III
Creator III
Author

Hi,

Thanks for your suggestion...

Just for simplification i have given start and end dates for every products. Below given is the code

but i think i have missed something important thing because below given code generating synthetic key. I have tried it by one another way by drooping  Product_UIN at the end but by doing this I am not getting UINNo.


Can you please help in correcting below given code..

Issuance:

LOAD Policy_no,

    Policy_no as Policy_Issuance

//    Year,

//    Month,

//    Channel,

//    Date

FROM

(ooxml, embedded labels, table is Issuance);

Overall:

LOAD Policy_no,

    Policy_no as Policy_Premium,

    Year,

    Month,

    Channel,

    Issuance_Date,

    ProductCode

FROM

(ooxml, embedded labels, table is Sheet1);

Product_UIN:

LOAD ProductCode,

    UINNo,

    Start_DT,

    END_DT

FROM

(ooxml, embedded labels, table is Sheet1);

Premium:

LOAD Policy_no as Policy_Premium,

//    Year,

//    Month,

//    Channel,

    Premium

FROM

(ooxml, embedded labels, table is Sheet1);

IntervalMatchTable:

IntervalMatch(Issuance_Date, ProductCode)

LOAD

      Start_DT, END_DT,ProductCode

RESIDENT

    Product_UIN;

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Ok, try joining the intervalmatch table with the Overall table.

LEFT JOIN (Overall)

IntervalMatch(Issuance_Date, ProductCode)

LOAD

      Start_DT, END_DT,ProductCode

RESIDENT

     Product_UIN;

You'll still have one synthetic key left after that, but that's not a problem. If you want to get rid of that one as well you can next left join the Product_UIN table to the Overall table and then drop the Product_UIN table.


talk is cheap, supply exceeds demand
pra_kale
Creator III
Creator III
Author

You are the Best Gysbert...

You have solve the problem in a fraction of second..

Thank you very much..

In real scenario i have more complex data model than what i have created here for testing purpose. But if i am not wrong the logic will still remain the same of interalMatch function and afterwords doing left join with main table which have Issuance dates.

Thanks again for your guidance.