Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to find number of rows in table and put in variable

I want to find the number of rows in a table, and pass that value to another program via a QV variable.

I tried (in my script)

LET vNumRows=NoOfRows('Daily CAR Table') <-- I also tried 'CH12', "CH12", "Daily CAR Table", but always got NULL

but that returns NULL.

The only other way I could see to do it would be to create a macro using table.GetRowCount, but then Henric might be upset with me ;}.

Any thoughts?

Thanks,

Kevin

10 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

This discussion is a bit confusing in that it isn't entirely clear to me which rows you want to count. Therefore first a few rules:

  1. UI objects cannot be accessed from inside a reload script
    So if 'Daily CAR table' is some kind of straight/pivot table (cf. 'CH12'), a LET/SET statement is never going to return anything because the engine cannot find that particular parameter value.

  2. A logical table (i.e. one that occurs in the Table Viewer) can be questioned to return the number of rows in your reload script through the table function NoOfRows(). But of course, the first thing the reload engine does when starting the execution of your script is to wipe all logical tables clean (and by extension all UI objects too). After the initial SET statements, there isn't any data left to report on. You should place your LET statement after the table LOAD statement that fills the table in question.

  3. The NoOfRows() chart interrecord function can only be used in an expression in a table column, and only references the containing table. If you want to count the rows in a UI table and put that one in a text box or in a continuously updated variable, the simplest method is to use =Count()

For a logical table, put your assignment in the right spot. For a UI object, you can use a trigger and a macro like the one from your last post. However, the macro better stores the value returned by GetRowCount right into the variable by itself. See Re: howmany rows in a table

BTW this question looks analogous to Re: Number of rows in straight/pivot table into a variable?  What's wrong with that discussion?