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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

having clause with count

I have a script, where I am loading the count of Employees in the preceeding load. Even if the EmpId exists 2 or more times it shows the count as 1 only. I want to have the count of employees as 2 if there are 2records of that employee in the table.

LOAD *

WHERE EmpIDs = 1;

LOAD EmpID, count(EmpID) as EmpIDs, SOID,SONAME,ProjectID,AssignmentStartDate,AssignmentEndDate,FactID

RESIDENT OrderTable

WHERE AssignmentStartDate >= 20110101 and AssignmentEndDate <= 20120101

GROUP BY EmpID,SOID,SONAME,ProjectID,AssignmentStartDate,AssignmentEndDate,FactID

1 Solution

Accepted Solutions
Not applicable
Author

Here send you your Having Test.qvs modified, hope this is wath you need.

Regards.-

View solution in original post

17 Replies
hic
Former Employee
Former Employee

The count of EmpID will always be 1 if you have EmpID in the group by clause. So, remove it from the group by clause and it will work.

/HIC

Not applicable
Author

If I remove its not showing any data...

Not applicable
Author

Is the count of employees to be finally shown in chart front end?

hic
Former Employee
Former Employee

You need to replace the "EmpID" with "Only(EmpID) as EmpID" in the list of loaded fields, also.

HIC

Not applicable
Author

Robin: yes, I just want to show the count in a text if the EmpID exists only one time in the table.

Not applicable
Author

Henric: Yes it worked, but still I am getting employees whose entries are two times in the table.

hic
Former Employee
Former Employee

Even though you have a preceding load with a where clause demanding EmpIDs=1 ?

HIC

Not applicable
Author

From what i understand, can u just load the table plain as:

LOAD EmpID, EmpID, SOID,SONAME,ProjectID,AssignmentStartDate,AssignmentEndDate,FactID

RESIDENT OrderTable

WHERE AssignmentStartDate >= 20110101 and AssignmentEndDate <= 20120101;

\and then simply use count(distinct EmpID)?

Thanks,

Robinson

vincent_ardiet
Specialist
Specialist

Hi,

Just replace in your code:

count(EmpID) as EmpIDs

by:

count(1) as EmpIDs

And it will work.

Regards,

Vincent