Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
josephinetedesc
Creator III
Creator III

How to convert columns to rows?

Hi

I have a table that I can produce in QlikView that looks like this:

    

    

NameClock1typecount(type)
John28/08/2014stop1
John11/11/2014reset1
John16/12/2014stop1
John10/02/2015reset1
John17/02/2015stop1
Paul1/03/2016stop1
Paul10/03/2016reset1
Paul24/03/2016stop1
George28/08/2014stop1
George24/03/2016reset1
George10/03/2016stop1
George1/03/2016reset1
George17/02/2015stop1
George10/02/2015reset1
George16/12/2014stop1
George11/11/2014reset1

I would like it to look like this:

     

Namestop1reset1stop2reset2stop3reset3stop4reset4stop5
John28/08/201411/11/201416/12/201410/02/201517/02/2015
Paul1/03/201610/03/201624/03/2016
George28/08/201424/03/201610/03/20161/03/201617/02/201510/02/201516/12/201411/11/2014

I suspect I will need hight level programming skills?

The headings stop1, reset 1, stop2, reset2 etc could just as easily be 1,2, 3, 4 etc

Is there something I could do with count(type) column? - I only did this so that I could make a pivot table.

If you could point me in the right direction I will research some more.

Thank you

Jo

1 Solution

Accepted Solutions
MarcoWedel

Hi,

besides the sorting issue Peter already mentioned, maybe one solution could be:

QlikCommunity_Thread_295890_Pic1.JPG

table1:

LOAD RecNo() as ID,

    Name,

    Clock1,

    type&AutoNumber(RecNo(),Hash128(Name,type)) as type

FROM [https://community.qlik.com/thread/295890] (html, codepage is 1252, embedded labels, table is @1);

hope this helps

regards

Marco

View solution in original post

7 Replies
bramkn
Partner - Specialist
Partner - Specialist

Crosstable maybe? this does work the other way around. Not sure if it will work for you as well. But it is a direction.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Getting some sort of order out of your original table is quite a challenge.

If we consider just Name = George, then how do the Resets relate to their corresponding Stops? The Clock1 values are pretty useless, as that would mean that for George his last line would match the first one and reset4 in your target table would suddenly be called reset1...

Can you explain what the logic is behind the combinations in you example?

[Edit] Sorry, no 'Starts', just 'Stops'

MarcoWedel

Hi,

besides the sorting issue Peter already mentioned, maybe one solution could be:

QlikCommunity_Thread_295890_Pic1.JPG

table1:

LOAD RecNo() as ID,

    Name,

    Clock1,

    type&AutoNumber(RecNo(),Hash128(Name,type)) as type

FROM [https://community.qlik.com/thread/295890] (html, codepage is 1252, embedded labels, table is @1);

hope this helps

regards

Marco

josephinetedesc
Creator III
Creator III
Author

Ah the logic!

The idea is that those "pesky users" want only "real" time to be used in their kpi data.  So they may do a task but take time out for a reason and they do not want that missing time to be calculated.

So John - he might just do a task in 2 days,

Paul - might take 10 days - but he had a break of 4 days (and those 4 days are not necessarily consecutive days)

What I meant was that I can sort the dates in order but if I can get them into columns I can just rename the column names with no impact.

Hope that makes sense!

Jo

josephinetedesc
Creator III
Creator III
Author

Thank you Marco

I cannot open QlikView files from home - so I will need to do this from work! 

I love working with QlikView - QlikSense -not so much

JO

josephinetedesc
Creator III
Creator III
Author

so to understand:

function Hash128 is to make the number in type and the Name unique - it does this on the fly. ?????

I make a pivot table and it works ...

Now another question:  I used this line in my code

'stop ' &AutoNumber(RecNo(),Hash128(Name ,'stop')) as type  -  this gives stop 1

I would like it to look like this: 1 stop   (that way when I sort the by type I will get them in order ie 1 stop, 1 reset, 2 stop, 2 reset etc.

Thank you Marco


MarcoWedel

Hi,

Yes, I used the Hash128() function to get unique AutoIDs for the Autonumber() function.

As for your second question, you could as well skip the Hash function when using a static 'stop' parameter.

AutoNumber(RecNo(),Name) should already result in your required sorting order.

hope this helps

regards

Marco