Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
keerthanagowsi
Contributor III
Contributor III

Generic load with Dynamic header column headers

Hi All,

I have a requirement in which i have to pivot a table and bring the row in to column view.

I used generic load and achieved the required result. 

EX:

Name Qtr-yrSalary
   
ABCQ4-20191000
ABCQ1-20202000
ABCQ2-20203000
DEFQ4-20192500
DEFQ1-20203500
DEFQ2-20204500

 

NameQ4-2019Q1-2020Q2-2020
ABC100020003000
DEF250035004500

 

But I have to show the column headers as below like

NameQQ+1Q+2
ABC100020003000
DEF250035004500

 

So that in the next quarter, even though the column Q4-2019 is not available in my data, it will not create any issue in my dashboard.

Can anyone help me with this requirement as i got stuck here  for more than 2 days.

Thanks in advance.

Regards,

keerthana

1 Solution

Accepted Solutions
MayilVahanan

HI @keerthanagowsi 

Might be, try like below before generic load

Sample:

LOAD * INLINE [
Name , Qtr-yr, Salary
ABC, Q4-2019, 1000
ABC, Q1-2020, 2000
ABC, Q2-2020, 3000
DEF, Q4-2019, 2500
DEF, Q1-2020, 3500
DEF, Q2-2020, 4500
];

Temp:
Load Distinct [Qtr-yr] Resident Sample;

Join(Sample)
LOAD *, if(RowNo()=1, 'Q', 'Q+'&(RowNo()-1)) as Qtr Resident Temp;

DROP Table Temp;

 

Based on above script, we will get Q, Q+1,Q+2 values as one column as 'Qtr'. After that, you can use ur script

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

6 Replies
MayilVahanan

HI @keerthanagowsi 

Might be, try like below before generic load

Sample:

LOAD * INLINE [
Name , Qtr-yr, Salary
ABC, Q4-2019, 1000
ABC, Q1-2020, 2000
ABC, Q2-2020, 3000
DEF, Q4-2019, 2500
DEF, Q1-2020, 3500
DEF, Q2-2020, 4500
];

Temp:
Load Distinct [Qtr-yr] Resident Sample;

Join(Sample)
LOAD *, if(RowNo()=1, 'Q', 'Q+'&(RowNo()-1)) as Qtr Resident Temp;

DROP Table Temp;

 

Based on above script, we will get Q, Q+1,Q+2 values as one column as 'Qtr'. After that, you can use ur script

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
keerthanagowsi
Contributor III
Contributor III
Author

Thank you @MayilVahanan  , I will try this and update on the output.

keerthanagowsi
Contributor III
Contributor III
Author

This solution works great 🙂 . Thankyou @MayilVahanan 

keerthanagowsi
Contributor III
Contributor III
Author

Hi @MayilVahanan ,

Following the same topic, just a small alteration in the requirement shared, added Date column in the excel.

Name QRDateSalary
    
ABCQ4-201921/11/20201000
ABCQ1-202021/11/20202000
ABCQ2-202021/11/20203000
DEFQ4-201921/11/20202500
DEFQ1-202021/11/20203500
DEFQ2-202021/11/20204500
ABCQ1-202021/12/2020500
ABCQ2-202021/12/20202000
ABCQ3-202021/12/2020400
DEFQ1-202021/12/2020250
DEFQ2-202021/12/20203600
DEFQ3-202021/12/20204500


and the expected output is 

NameDateQQ+1Q+2
ABC21/11/2020100020003000
DEF21/11/2020250035004500
ABC21/12/20205002000400
DEF21/12/202025036004500

 

so as per the script you shared, is it possible to calculate the row number for each date.

For example, 

whenever the date changes, the row count should start again from 1. I think it is possible to achieve using For each loop, but I don't know how to apply it. Can you help me with this?

Thanks,

keerthana

MayilVahanan

Hi @keerthanagowsi 

Try like below

LOAD *, If(Name <> Previous(Name), 'Q', 'Q+'&(Peek(Num)+1)) as Qtr, If(Name <> Previous(Name) , 0, Peek(Num)+1) as Num INLINE [
Name , QR, Date, Salary
ABC, Q4-2019, 21/11/2020, 1000
ABC, Q1-2020, 21/11/2020, 2000
ABC, Q2-2020, 21/11/2020, 3000
DEF, Q4-2019, 21/11/2020, 2500
DEF, Q1-2020, 21/11/2020, 3500
DEF, Q2-2020, 21/11/2020, 4500
ABC, Q1-2020, 21/12/2020, 500
ABC, Q2-2020, 21/12/2020, 2000
ABC, Q3-2020, 21/12/2020, 400
DEF, Q1-2020, 21/12/2020, 250
DEF, Q2-2020, 21/12/2020, 3600
DEF, Q3-2020, 21/12/2020, 4500
];

DROP Field Num;

output:

MayilVahanan_0-1606886011997.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
keerthanagowsi
Contributor III
Contributor III
Author

Hi,

It's Not working for my huge data