Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How can we count the number of entries in text object without any field?

Hi Guys,

I am stuck at a point where I want to count the number of entries in a text object.Tried my best but couldn't get a way out to solve this. Any sort of help will be highly appreciated. I have tried explaining my problem below in detail:

There is an expression in text object which will look some thing like :

=Count({<ABC={1}, XYZ={'$(vDRG1)'}, XYZZ = {'$(vDRG1)'}>}ABC) & ',' &

Count({<ABC={2}, XYZ={'$(vDRG1)'}, XYZZ = {'$(vDRG1)'}>}ABC) & ',' &

Count({<ABC={3}, XYZ={'$(vDRG1)'}, XYZZ = {'$(vDRG1)'}>}ABC) & ',' &

.

.

.

all the way till

.

Count({<ABC={60}, XYZ={'$(vDRG1)'}, XYZZ = {'$(vDRG1)'}>}ABC)

The output of this expression will be like: 0,0,2,0,0,0,0.......6,3,0,0,0,0

>> Now I want to get the count of entries till the last non zero values. In the above example it should return = 60-4= 56

Below table will give more clarity

Header 1Header 2Header 3Header 4Header 5Header 6Header 7Header 8Header 9Header 10Header 11

Desired output

000471600310
11000000002
00000000000
00779020007

Thank you,

Sagar Gupta

1 Solution

Accepted Solutions
maxgro
MVP
MVP

may be

=substringcount(replace(rtrim(replace('0,0,1,12,0,0,0,10,0,0,0,0,0,0,0', ',0', ' ')),' ', ',0'), ',')+1

replace('0,0,1,12,0,0,0,10,0,0,0,0,0,0,0', ',0', ' ')

rtrim blank --> delete blank (,0) at the rigth of the string

replace(........, ' ', ',0')  --> same as initial string but without ,0 at the rigth

substringcount --> count ,

View solution in original post

4 Replies
Not applicable
Author

I just got an idea but am not sure how to do that

Cumulative sum from right to left will replace zero values

Not applicable
Author

Hi Sagar,

You will need to repeat your long expression at least twice.

INPUT - 0,0,0,4,7,1,6,0,0,3

substringcount('INPUT', ',')  +1 - substringcount(',' & 'INPUT' & ',' , ',0,')

First part gives the number of values. (number of commas + 1)

Second part gives the number of zero values. (Am adding commas at beginning and end of your output so that i can count 0s alone and avoid cases like 10,20,30 etc which also contain a 0.)

maxgro
MVP
MVP

may be

=substringcount(replace(rtrim(replace('0,0,1,12,0,0,0,10,0,0,0,0,0,0,0', ',0', ' ')),' ', ',0'), ',')+1

replace('0,0,1,12,0,0,0,10,0,0,0,0,0,0,0', ',0', ' ')

rtrim blank --> delete blank (,0) at the rigth of the string

replace(........, ' ', ',0')  --> same as initial string but without ,0 at the rigth

substringcount --> count ,

Not applicable
Author

Hi Grossi,

Thanks a lot, It worked the way I wanted it to be.

Much Thanks