How to convert a list with key-value pairs grouped by ID into rows (keys become columns)

I have a list, that stores for a set of people, a list of key value pairs, where there are many keys (like 40-60). Approximately like so:

PID Key Value
A name Foo
A height 12
A weight 421
A grade 12
A
B name Bar
B height 124
B weight 98
B grade 10
B
C name Baz
C height 412
C weight 12
C grade 93
C

I would like to turn it into a list, where each person has a single row, and the different keys become columns, like so

PID name height weight grade
A Foo 12 421 12
B Bar 124 98 10
C Baz 412 12 93

All the keys may not always be present, so sometimes there are a few more or less elements to combine into a single row. Any help would be appreciated!

1 Like

I assume when you say “list” you mean you have the data in a table as displayed in your example correct?

If so this is a job for a Pivot Node.

Select PID as group column, key as pivot column and the in manual aggregation tab select Value column and use aggregation method “First”.

Important: This assumes that there are no duplicate keys for the same PID - e.g for PID A there’s always only one height, weight etc.

3 Likes

This worked. Thank you very much!

Glad I could help. If this solved it flagging the post as solution is much appreciated as it may help people in the future find a solution for this problem quicker :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.