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

Set analysis question

Hi Everyone,

Thank you for taking a look at my question.

Here's the scenario:  I have a list of transactions and each transaction is made up of multiple line items that each belong to one department and have a net sales associated.  The data source is below:

TransactionKeyDepartmentNetSales
1A54
1B90
1E4
2B35
2C98
3D32
3B76
3F59
4A39
4C4
4F26

What I'm trying to do is create a straight table with Department as the dimension and have an expression that sums the entire transaction net sales for each transactions that has an item sold from the department.  The results would look like this:

DepartmentNet Sales
A217
B448
C202
D167
E148
F236

For example, department A has net sales of 217 because it TransactionKey 1 and 4 have an items sold from department A so I summed both of those transactions.

I've made several attempts to get the expression working by trying to aggregate Net Sales by TransactionKey but I'm not able to get it working properly.  If anyone could provide an example of the correct syntax I would greatly appreciate it!

Thank you,

Dan

1 Solution

Accepted Solutions
qliksus
Specialist II
Specialist II

Hi,

Please use the expression as

sum(Aggr(Sum(Total <TransKey> NetSale),Dept,TransKey))

For reference

Dept sum(Aggr(Sum(Total <TransKey> NetSale),Dept,TransKey))
A217
B448
C202
D167
E148
F236

View solution in original post

14 Replies
rustyfishbones
Master II
Master II

Hi,

I am not sure I understand the question, SUM(NetSales) with Department as Dimension should give you what you need

See attached

but maybe you have not explained it properly, or I have not understood it

Not applicable
Author

Thanks for the reply Alan.

That doesn't work because it only sums the line items that are in that department.  I want the total sales of the entire transaction for every transaction that has at least 1 item in the department.

For department A I'm looking for a value of 217 (everything in transaction 1 and 4 because both of those have an item in department A) while using Sum(NetSales) will only give me 93 (54 + 39).

I hope this clarifies my question.

Regards

Not applicable
Author

Try something like this:

Sum(aggr(sum(NetSales), TransactionKey))

with Department as dimension

Not applicable
Author

Hi Claudio,

I appreciate the feedback but that doesn't produce the correct results.  I get this with your formula:

DepartmentNet Sales
517
A217
B133
C0
D167
E0
F0

Thanks,

Dan

rustyfishbones
Master II
Master II

Hi Dan,

How do you expect to get Department A NetSales 217?

Are the NetSales not Summing to 93 based upon your example

Not applicable
Author

OK, i you should group by Department too,

sum(aggr(sum(NetSales),TransactionKey,Department))

Not applicable
Author

Alan,

I get 217 by adding up all 6 lines that belong to transaction 1 and 4.  What I need to do is find the total transaction net sales for every transaction that has at least 1 item in a given department.  So in department A's case there are two transactions that have an item in department A and those are transactions 1 and 4.  Therefore I want the total net sales for transaction 1 and 4 which is 217.

I don't want the 93 result because that only includes 2 lines (the one department A line from transaction 1 and the one department A line from transaction 4).  I need all 6 lines from the two transactions.

Thanks,

Dan

Not applicable
Author

Thanks again Claudio but that still didn't do the trick.  I get these results:

DepartmentNet Sales
517
A93
B201
C102
D32
E4
F85
rustyfishbones
Master II
Master II

that will give the same result as SUM(NetSales)