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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

scripting

Hi All,

How to achieve below scenario. for nov initially 3names are there then we have to check out of these 3 how many are present in dec ,then now for dec its 2 . so for jan we have to check from dec . so output is 2 . now for feb we have to check in jan and output is 1. similarly for other months

Input
year monthname
2011Nov a
2011Nov b
2011Nov c
2011Decb
2011Dece
2011Decc
2012Janb
2012Janc
2012Febd
2012Febb
output
Nov_2011Dec_2011Jan_2012Feb_2012
Nov_20113221
Dec_2011321
Jan_201221
Feb_20122
3565
1 Solution

Accepted Solutions
effinty2112
Master
Master

Hi Kulwant,

Try:

Data:

LOAD

Date#(year&Upper(month),'YYYYMMM') as Month,

name;

LOAD * INLINE [

    year, month, name

    2011, Nov, a

    2011, Nov, b

    2011, Nov, c

    2011, Dec, b

    2011, Dec, e

    2011, Dec, c

    2012, Jan, b

    2012, Jan, c

    2012, Feb, d

    2012, Feb, b

];

For i = 1 to FieldValueCount('Month')

For j = $(i) to FieldValueCount('Month')

Let vMonth1 = FieldValue('Month',$(i));

Let vMonth2 = FieldValue('Month',$(j));

Temp:

LOAD

name

Resident Data Where Month = '$(vMonth1)';

Inner Join

LOAD

name

Resident Data Where Month = '$(vMonth2)';

Count:

LOAD

Count (name) as Cnt Resident Temp;

Let vCount = Peek('Cnt',-1,'Count');

Drop Tables Temp,Count;

Result:

LOAD

'$(vMonth1)' as Month1,

'$(vMonth2)' as Month2,

'$(vCount)' as Count

AutoGenerate 1;

Next j;

Next i;

Giving:

Month1 Month2 2011NOV2011DEC2012JAN2012FEB
2011NOV 3221
2011DEC 321
2012JAN 21
2012FEB 2

Cheers

Andrew

View solution in original post

4 Replies
effinty2112
Master
Master

Hi Kulwant,

Try:

Data:

LOAD

Date#(year&Upper(month),'YYYYMMM') as Month,

name;

LOAD * INLINE [

    year, month, name

    2011, Nov, a

    2011, Nov, b

    2011, Nov, c

    2011, Dec, b

    2011, Dec, e

    2011, Dec, c

    2012, Jan, b

    2012, Jan, c

    2012, Feb, d

    2012, Feb, b

];

For i = 1 to FieldValueCount('Month')

For j = $(i) to FieldValueCount('Month')

Let vMonth1 = FieldValue('Month',$(i));

Let vMonth2 = FieldValue('Month',$(j));

Temp:

LOAD

name

Resident Data Where Month = '$(vMonth1)';

Inner Join

LOAD

name

Resident Data Where Month = '$(vMonth2)';

Count:

LOAD

Count (name) as Cnt Resident Temp;

Let vCount = Peek('Cnt',-1,'Count');

Drop Tables Temp,Count;

Result:

LOAD

'$(vMonth1)' as Month1,

'$(vMonth2)' as Month2,

'$(vCount)' as Count

AutoGenerate 1;

Next j;

Next i;

Giving:

Month1 Month2 2011NOV2011DEC2012JAN2012FEB
2011NOV 3221
2011DEC 321
2012JAN 21
2012FEB 2

Cheers

Andrew

Anonymous
Not applicable
Author

Hi Andrew

how to make chart which you have made final output?? what is the expression you are using??

Thanks and Regards

effinty2112
Master
Master

Hi Kulwant,

The chart is a pivot table with dimensions Month1 & Month2. Expression is Count or Sum(Count) if you want partial sums on Month1 like:

Month1 Month2 2011NOV2011DEC2012JAN2012FEB
2011NOV 3221
2011DEC 321
2012JAN 21
2012FEB 2
Total 3 5 6 5

I'm not sure how meaningful the sums are.

Regards

Andrew

antoniotiman
Master III
Master III

May be this

Temp:
LOAD year,month,MonthName(MakeDate(year,Month(Date#(month,'MMM')))) as MonthName,name
Inline [
year month name 
2011 Nov a 
2011 Nov b 
2011 Nov c 
2011 Dec b 
2011 Dec e 
2011 Dec c 
2012 Jan b 
2012 Jan c 
2012 Feb d 
2012 Feb b
]
(delimiter is spaces);

Join
LOAD name,MonthName as MonthName1
Resident
Temp;