Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
M_Lhermitte
Contributor
Contributor

Count distinct in script

Hello everyone,

I am currently trying to use the "count distinct" in my script. However, I face an issue when loading the data. Qlik tells me that I have an "invalid expression". Could you please help me solving my issue?

Thanks,

Marguerite

 

The script is:

NoConcatenate
[inst_per_course_1]:

Load
[Course],
[CourseIdentifier],
[CourseTypeFamily],
[CustomerType],
[TraineeCode],
Trigram,

count(DISTINCT Trigram) as nb_instructor

resident [MyTable]
group by Course
;

 

 

Is it better to used 2 separate tables? (I also have an "invalid expression" issue when loading data.) as:

NoConcatenate
[inst_per_course_1]:

Load
[Course],
[CourseIdentifier],
[CourseTypeFamily],
[CustomerType],
[TraineeCode],
Trigram

resident [MyTable]
;

NoConcatenate
[inst_per_course_2]:

Load *,

count(DISTINCT Trigram) as nb_instructor

resident [inst_per_course_1]
group by [Course]
;

Labels (4)
1 Reply
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

The error is coming because you have not included all the other fields in group by list. 

Try this.

The script is:

NoConcatenate
[inst_per_course_1]:

Load
[Course],
[CourseIdentifier],
[CourseTypeFamily],
[CustomerType],
[TraineeCode],
Trigram,

count(DISTINCT Trigram) as nb_instructor

resident [MyTable]
group by [Course],
[CourseIdentifier],
[CourseTypeFamily],
[CustomerType],
[TraineeCode],
Trigram;

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!