Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
dawgfather
Creator
Creator

Count If Expression

I am loading a SQL query into a table. I have records for items (laptops) that connect to different servers of different types, so there are likely multiple entries for some laptops.

I want to create an expression to count the number of laptops that have connected both of the 2 types of servers ("old" and "new") - but they have to have connected to BOTH types. If a laptop connects to one or the other, don't count it. If there is a record of it connecting to one and then also an entry connecting to the other, then count those (even better if I could come up with a Yes/No type expression to say it's connected to both, but a count will do).

Some sample data and the last column is whether I would expect it to be counted or not.

I should end up with a count of 3 (DEF123, ABC345 and DEF456) that connected to both types.

In my head my logic is something like count LAPTOP if there is a record matching (where) ServerGroup = 'old_servers' AND where there is a record matching (where) ServerGroup = 'new_servers'. But I cannot seem to get anything. Everything I do seems to do this at each record's level so the counts are always 1.

Laptop

field

Server

field

ServerGroup

field

LastSeenDate

field

LastSeenOld

expression

LastSeenNew

expression

Desired outcome

(comment)

ABC123Old1old_servers11/2/201611/2/2016-Not counted
DEF123Old2old_servers11/4/201611/4/2016-Counted
DEF123New5new_servers11/6/2016-11/6/2016Counted
ABC345Old1old_servers11/5/201611/5/2016-Counted
ABC345New6new_servers11/6/2016-11/6/2016Counted
DEF456Old3old_servers11/5/201611/5/2016-Counted
DEF456New7new_servers11/8/2016-11/8/2016Counted
DEF678New8new_servers11/8/2016-11/8/2016Not counted
ABC789New7new_servers11/9/2016-11/9/2016Not counted
1 Solution

Accepted Solutions
sunny_talwar

May be this:

If(Count(DISTINCT ServerGroupField) = 2, 'Yes', 'No')

in Text box obect, may be like this:

For count

Count(DISTINCT {<LaptopField = {"Count(DISTINCT ServerGroupField) = 2"}>} LaptopField)

For list

Concat(DISTINCT {<LaptopField = {"Count(DISTINCT ServerGroupField) = 2"}>} LaptopField, ', ')

View solution in original post

4 Replies
vishsaggi
Champion III
Champion III

Try this in your Pivot table and supress zero values in presentation tab.

Dim: All your dimentsion

Expr: = Sum(Aggr(Count({< ServerGroupfield = {'old_servers','new_servers'}>} Laptopfield), Laptopfield))

Or

Expr:  Count(TOTAL < Laptopfield> {< ServerGroupfield = {'old_servers','new_servers'}>} Laptopfield)

sunny_talwar

May be this:

If(Count(DISTINCT ServerGroupField) = 2, 'Yes', 'No')

in Text box obect, may be like this:

For count

Count(DISTINCT {<LaptopField = {"Count(DISTINCT ServerGroupField) = 2"}>} LaptopField)

For list

Concat(DISTINCT {<LaptopField = {"Count(DISTINCT ServerGroupField) = 2"}>} LaptopField, ', ')

dawgfather
Creator
Creator
Author

The option for "If(Count(DISTINCT ServerGroupField) = 2, 'Yes', 'No')" worked great in a pivot.

I could then collapse the other details and get a Yes/No. Only hitch is that I have no way to sort on those once the details are expanded because then each line item only has 1 ServerGroupField and therefore the IF statement results in a "No". But it gets me much closer than I was.

Thank you.

sunny_talwar

May be try this:

If(Count(DISTINCT TOTAL <LaptopField> ServerGroupField) = 2, 'Yes', 'No')