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: 
trevorcrow
Contributor II
Contributor II

Display Value Based on Count of Records Being Displayed

Hello Qlik Community,

I am trying to display a value for each record that my query brings back based on what third of the overall distinct record count being displayed is.  For example, if I have 9 records being displayed, I want a column to display text values based on what 1/3rd of records it is in. 

As shown in the table below, this is my desired outcome, based on how many rows are being displayed, I'd like some calculations to essentially group the rows into thirds, so I can display a value using an IF statement based on what third the row is bucketed into.

Order Number Record/RowNumber Third Value
100641 1 1st Third Value 1
25002 2 1st Third Value 1

106503

3 1st Third Value 1
100431 4 2nd Third Value 2
6845 5 2nd Third Value 2
35454 6 2nd Third Value 2
818281 7 3rd Third Value 3
65771 8 3rd Third Value 3
9846 9 3rd Third  Value 3

 

I hope this makes sense.  Any assistance would be appreciated!

Labels (1)
1 Reply
henrikalmen
Specialist
Specialist

This expression will hopefully give you what you need (a number from 1 to 3 depending on what third of all rows the particular row belongs to, you can use that number to create the text field value as you want it):
ceil(rowno(total) / (ceil(noofrows(total)/3)))
 
The second part of this expression - ceil(noofrows(total)/3) - calculates how many rows that should go into each third, and by dividing each row number with that number we can find out the correct third.
 
Be aware that if the total number of rows are not evenly divided by 3, the last third will contain fewer rows than the other. If for example you have 10 rows, there will be four rows in 1st Third and 2nd Third, but only two rows in the 3rd Third.
 
Naturally, the "thirds classification" is not tied to each individual row's data, so if you sort the table differently the rows currently on top will still be 1st Third.