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: 
Not applicable

Turn several rows into one

I have a straight table with sales info in columns like this:

SaleID Amount SalesPerson Region

A sale can have multiple Sale Persons on it. So I end up with 2 rows for 1 sale. Like this:

SaleID Amount SalesPerson Region

1 100 Tim USA

1 100 Sam USA

I would like to have it be on only one row:

SaleID Amount SalesPerson Region

1 100 Tim, Sam USA

Can I make an expression do this somehow? Thanks!

1 Solution

Accepted Solutions
erichshiino
Partner - Master
Partner - Master

When your table is already loaded (I will call it OriginalTable)

you can make:

load SaleIdD, Amount, concat(SalesPerson',', ') as SalesPeople,

//if you don't change at least one field name you will have to use noconcatenate before LOAD statement

Region

resident OriginalTable

group by SaleID, Amount, Region;

drop table OriginalTable;// if you don't drop it's better to change field names

View solution in original post

3 Replies
erichshiino
Partner - Master
Partner - Master

When your table is already loaded (I will call it OriginalTable)

you can make:

load SaleIdD, Amount, concat(SalesPerson',', ') as SalesPeople,

//if you don't change at least one field name you will have to use noconcatenate before LOAD statement

Region

resident OriginalTable

group by SaleID, Amount, Region;

drop table OriginalTable;// if you don't drop it's better to change field names

hector
Specialist
Specialist

Hi

maybe you can use concat() and group by clauses like this

Load

SaleID,
Amount,
Region,
Concat(SalesPerson,',') as SalesPersonConcat
from/resident
group by
SaleID,
Amount,
Region

Rgds

PS. depending on your data, maybe you can use max(Amount) or Avg(Amount) or Sum(Amount), instead of grouping by the field

Not applicable
Author

I ended up just using the concat(SalesPerson',', ') in a expression and it works! hoooray!!