Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
April 13–15 - Dare to Unleash a New Professional You at Qlik Connect 2026: Register Now!
cancel
Showing results for 
Search instead for 
Did you mean: 
sifatnabil
Specialist
Specialist

Aggregation problem

Hi,

I have a table structure like this:

PrimaryKeyTradeIDElectronicVoiceVolume
12311(blank)X10
12411X(blank)5
12511(blank)X10

What I want do is:

For each unique TradeID,

if Electronic contains X in any row AND if Voice contains X in any row,

count(distinct TradeID) and

sum(Volume)


I know this involves some sort of aggregation and I tried this in a textbox:

count(distinct if(len(Electronic)>0 and len(Voice)>0, TradeID))


But this returns an error.

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

count({<TradeID=p({<Electronic={'X'}>}TradeID)*p({<Voice={'X'}>}TradeID)>} DISTINCT TradeID)

sum({<TradeID=p({<Electronic={'X'}>}TradeID)*p({<Voice={'X'}>}TradeID)>} Volume)


talk is cheap, supply exceeds demand

View solution in original post

8 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

count({<TradeID=p({<Electronic={'X'}>}TradeID)*p({<Voice={'X'}>}TradeID)>} DISTINCT TradeID)

sum({<TradeID=p({<Electronic={'X'}>}TradeID)*p({<Voice={'X'}>}TradeID)>} Volume)


talk is cheap, supply exceeds demand
JonnyPoole
Former Employee
Former Employee

Try something like this:

It checks if 'X' is in any row of Electronic and any row of Voice for each TradeID. 

If its in both at least one time, then count the tradeID otherwise don't count the tradeId

=count( DISTINCT 

  if(

  aggr(SubStringCount(Concat(DISTINCT Electronic),'X'),TradeID)

  and

  aggr(SubStringCount(Concat(DISTINCT Voice),'X'),TradeID)

  , TradeID)

)

Capture.PNG.png

sifatnabil
Specialist
Specialist
Author

Thanks Gysbert, sorry I should actually correct this line in my question:

if Electronic contains X in any row AND if Voice contains X in any row,


to


if Electronic is not blank in some rows AND if Voice is not blank in some rows


That's why I used concat(len(Electronic)>0 ..


Could you incorporate len into your solution?

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Ah, that's a lot easier. count({<Electronic={'X'},Voice={'X'}>} distinct TradeID)


talk is cheap, supply exceeds demand
sifatnabil
Specialist
Specialist
Author

Sorry, the reason I can't select X is because X can be any string, like ABC or DVD, how can I amend it like count({<Electronic={'Any value except blank'},Voice={'Any value except blank'}>} distinct TradeID) ?

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Use '*' instead of 'X'.


talk is cheap, supply exceeds demand
sifatnabil
Specialist
Specialist
Author

Thanks, actually your original answer worked but with '*'. Thanks! And what if I wanted the inverse? i.e. can I use count({<TradeID=p({<Electronic-={'*'}>}TradeID)*p({<Voice-={'*'}>}TradeID)>} DISTINCT TradeID) ?


Set analysis doesn't seem to allow -=


Also, what's the best way to display this in chart format if I want the dimension to be date or any other field?

sifatnabil
Specialist
Specialist
Author

bump.