Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
rahulsud007
Creator
Creator

Storing QVD w.r.t to particular field name in script.

Hi guys, I would like to store the table with respect to its field value.

I have a table with SalesID, Name, Zone, Cateogry   I need to store the data of each Cateogry into a qvd through QV script.

For eg.

 

SalesID  NameZone Cateogry
1ABCeastCategory1
2sceastCategory1
3dscwestCategory1
4sefwestCategory1
5aqwnorthCategory2
6wqanorthCategory2
7asdnorthCategory2

I need the date to be stored as category1.qvd, category2.qvd,

I don't want to use any hard corded functionality as I need to set it dynamically because there are more than 50 categories.

Kindly help, thanks in advance.

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try like:

T1:

Load * Inline [

SalesID, Name, Zone, Category

1, ABC, east, Category1

2, sc, east, Category1

3, dsc, west, Category1

4, sef, west, Category1

5, aqw, north, Category2

6, wqa, north, Category2

7, asd, north, Category2

];

Let vCount=FieldValueCount('Category');


For i=1 to $(vCount)

     Let vCategory=FieldValue('Category',$(i));

    NoConcatenate

    T11:

    Load

            *

    Resident T1 Where Category='$(vCategory)';

    STORE T11 into Category_$(vCategory).(qvd);

    DROP Table T11;

Next

View solution in original post

3 Replies
tresesco
MVP
MVP

Try like:

T1:

Load * Inline [

SalesID, Name, Zone, Category

1, ABC, east, Category1

2, sc, east, Category1

3, dsc, west, Category1

4, sef, west, Category1

5, aqw, north, Category2

6, wqa, north, Category2

7, asd, north, Category2

];

Let vCount=FieldValueCount('Category');


For i=1 to $(vCount)

     Let vCategory=FieldValue('Category',$(i));

    NoConcatenate

    T11:

    Load

            *

    Resident T1 Where Category='$(vCategory)';

    STORE T11 into Category_$(vCategory).(qvd);

    DROP Table T11;

Next

rahulpawarb
Specialist III
Specialist III

May be this:

//Load sample data

Data:

LOAD * INLINE [

SalesID, Name, Zone, Category

1, ABC, east, Category1

2, sc, east, Category1

3, dsc, west, Category1

4, sef, west, Category1

5, aqw, north, Category2

6, wqa, north, Category2

7, asd, north, Category2

8, lmn, south, Category3

9, pqr, south, Category3

];

//Load distinct Category values; this is used for looping purpose

tmpCategory:

LOAD Distinct

     Category

Resident Data;

//Loop through distinct Category values

FOR i = 0 to NoOfRows('tmpCategory')-1

//Get the Unique Category value

LET vCategory = Peek('Category', $(i), 'tmpCategory');

//Fetch the records associated with unique Category value

NoConcatenate

$(vCategory):

LOAD *

Resident Data

Where Category = '$(vCategory)';

//Store the result into QVD

STORE $(vCategory) INTO $(vCategory).QVD(qvd);

//Drop the intermediate table

DROP Table $(vCategory);

NEXT

//Drop the temporary table

DROP Table tmpCategory;

Regards!

Rahul Pawar

rahulsud007
Creator
Creator
Author

Thanks a lot tresesco‌ and Rahul both of the logic worked in this case.

Thanks a lot it was helpful