Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

johnsmithqv
New Contributor III

composite key

Please find the attached dashboard.

Where i am creating a composite key and need to get the year and month field selected simaltnaeously in the application.

I want year & month as filters.

I need 2012 jan to be filtered in the list box.

Please let me know

8 Replies
Partner
Partner

Re: composite key

you donot have data from 2012

I would recommend to use a master calender

sushil353
Honored Contributor II

Re: composite key

Hi,

It is better if you create master calendar in your application.

johnsmithqv
New Contributor III

Re: composite key

Thanks for the reply

Could you please provide me sample code for master calendar?

Re: composite key

Try this master calendar script code

DateData:

LOAD

YearStart( Today() ) + IterNo() as Date,

Rand() as Value

AutoGenerate 1

While (YearStart(Today()) + IterNo())  <= YearEnd(Today());

Final:

Load

*,

Date(Date) as DateNew

Resident DateData;

Master Calendar Generation Script

https://community.qlik.com/blogs/qlikviewdesignblog/2012/10/16/the-master-calendar

Regards

Anand

Re: composite key

Hi John, check this document: Master Calendar Generation Script

In this part of the script:

Load

    Min(InvoiceDate) AS MinDate,

    Max(InvoiceDate) AS MaxDate

RESIDENT Invoice;

MinDate should store the start date of the calendar and MaxDate the end date, it can be dynamic absed on data like in the sample, you can fixed the dates using Date('YourDate') or you can create a variable that sets the min and max dates and use the variables to assign values to MinDate and MaxDate.

johnsmithqv
New Contributor III

Re: composite key

Thanks everyone

However in my application i have only year and month i dont have any date field.

Please respond now

Re: composite key

Hi John, you can create only one record per month changing from:

Load Date(MinDate + IterNo() -1 ) AS InvoiceDate While (MinDate + IterNo() - 1) <= Num(MaxDate);


to:

Load Date(AddMonths(MinDate, IterNo() -1)) AS InvoiceDate While Date(AddMonths(MinDate, IterNo() -1)) <= Num(MaxDate);


Anyway, dont' worry too much for creating all dates, as it is another table you can create all dates without affecting your data. and if you load 5-6 years of dates there will be less than 2k extra records.

Re: composite key

I suggest some of the main points

1. Make Master Calendar

2. To connect with the Date field create the date field with Makedate function.

Ex:-

Load

Makedate(Year, Month) as Datefield

From Location;

Regards

Anand