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: 
venkatg6759
Creator III
Creator III

MergeMultiple rows into columns

Hello Everyone,

                          I have below table

   

DescVal
Errors1
CategoryLoan
Sub Category Loan Sold
LabelRecord Count

I Need to separate and make it show like this

Errors   Category   Sub Category      Label

1           Loan          Loan Sold            Record Count

Can anyone help me how to do this.

Thanks in advance,

Venkata

10 Replies
sunny_talwar

Try this:

Table:

Generic

LOAD 1 as Field,

  *

Inline [

Desc, Val

Errors, 1

Category, Loan

Sub Category, Loan Sold

Label, Record Count

];


DROP Field Field;


Capture.PNG

Clever_Anjos
Employee
Employee

Is your table

  1. A source (excel, sql, etc)
  2. An object?
venkatg6759
Creator III
Creator III
Author

It's not excel.It's coming from SQL.these are just 2 columns in that table.

Not applicable

Hi Venkat,

What is the DB you are using like Oracle, MySQL etc..

Thanks,
Sreeman

Colin-Albert

Generic Load can fix your data as suggested by Sunny T sunindia

This post has more details The Generic Load

johnw
Champion III
Champion III

Yet another example of a generic load. This is from one of my live applications, with a little unneeded complexity removed, hopefully without breaking it. Same idea as Colin_Albert‌'s link to hic's generic load, where the columns are all combined into one table instead of left as separate tables, just a slightly different approach to building that final table.

// Creates one Generic.* table per Facility Event LCID/Class
[Generic]:
GENERIC
LOAD
[Order Item]
,[Facility Event LCID/Class]
,[Manufacturing Result]
FROM ManufacturingInstructions.qvd (QVD)
;

// Build new flat table with distinct order items.
// This is faster than a load distinct.
[Flat]:
LOAD text(fieldvalue('Order Item',recno())) as [Order Item]
AUTOGENERATE fieldvaluecount('Order Item')

// For each table that still exists
LET i = 0;
DO WHILE i < nooftables()
    LET vTable = tablename($(i));
    // If it's one of our Generic.* tables
    IF  subfield(vTable,'.',1)='Generic' THEN
        // Add the field to our flat table.
        LEFT JOIN ([Flat])
        LOAD *
        RESIDENT [$(vTable)]
        ORDER BY [Order Item]
        ; 
        // And delete the Generic.* table
        DROP TABLE [$(vTable)]
        ; 
    ELSE
        // Not a Generic.* table. Skip past it.
        LET i = i + 1;
    ENDIF
LOOP

venkatg6759
Creator III
Creator III
Author

Will try this .But Generic Load worked for me .Later I merged column tables to main table by join.Thank you John

venkatg6759
Creator III
Creator III
Author

This was helpful colin .Thanks

johnw
Champion III
Champion III

If the generic load serves your needs, you're done. I wouldn't introduce complicated scripting like I show above to combine the fields into one table. I needed it so that I could store the result as a QVD. If you don't have that or another compelling reason to combine the fields, just leave them like the generic load builds them. I really should have mentioned that in my original post, but I wasn't thinking it through, just grabbing an example.