Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Mikko
Contributor
Contributor

Sum distinct with condition

Hi,

I´m quite new with Qlik and struggling with an expression. I´m trying to sum distinct ServiceLines per InvoiceNo whenever FlagMatched has a value. 

if((FlagMatched=1), sum(aggr(sum(DISTINCT ServiceLines), InvoiceNo)),0)

I have to use Distinct Service lines since the data has several updates for each matched invoice.

InvoiceNoServiceLinesFlagMatched
00120
00120
00241
00241
00360
00360
00481
00481

 

In this case the result what I´m after is 4+8=12

For some reason I´m getting the correct value with below expression when using filter FlagMatched=1 in GUI but as soon as I take it out, I don´t get any results.

All the tips are welcome!

2 Replies
tresesco
MVP
MVP

Try this:

 sum(aggr(sum(DISTINCT if(FlagMatched=1, ServiceLines)), InvoiceNo)),0)

Mikko
Contributor
Contributor
Author

Many thanks! Got it working with slight change to the expression

sum(aggr(sum(DISTINCT if(FlagMatched=1, ServiceLines,0)), InvoiceStatusKey))