Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how do i count distinct record in a loaded data and set the number of record to a variable after data loaded

Dear all,

I have a data table loaded from CSV as shown below. As you can see the field 'No' is repeated. How do i do the distinct count on that table based on the filed 'No'. and after that update a variable with this distinct count no?

Untitled.png

1 Solution

Accepted Solutions
effinty2112
Master
Master

Chee,

This is simpler than my first suggestion:

Let vCountNo = FieldValueCount('No');

View solution in original post

7 Replies
Not applicable
Author

or i can use maxstring(No) to retrieve the maximum number is '9'.

then how do i set this '9' to a variable created after data loaded?

PrashantSangle

Hi,

use system fields i.e.

$Table and $ Rows will give you required result.

Regards

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Not applicable
Author

ok. If want to to the maxstring(No) during the load script possible?

As i have a variable named 'vSheets' and during the load script. i want to set the vSheet to become maxstring(No)

effinty2112
Master
Master

Hi Chee,

try this in your script after the csv has been loaded

CountNo:

LOAD

Count(DISTINCT No) as CountNo

Resident Data;

Let vCountNo = Peek('CountNo',0,'CountNo');

Cheers

Andrew

effinty2112
Master
Master

Chee,

This is simpler than my first suggestion:

Let vCountNo = FieldValueCount('No');

Not applicable
Author

quite close. can i do some calculation within the peek? for example i want to minus Countno with 1?

effinty2112
Master
Master

Hi Chee,

Try:

Let vCountNo = FieldValueCount('No') -1;