Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Counting the number of times a word appears at the detail level

Hi All,

I would like to count the number of times a certain word appears at the detail level in the load script.

Data example: Invoice #1, detailid #30, producttype = 'washer'
Invoice #1, detailid #35, producttype = 'washer'

Answer example: Invoice #1, detailid #30, producttype = 'washer', washer count = #1
Invoice #1, detailid #35, producttype = 'washer', washer count = #2
Invoice #2, detailid #7, producttype = 'washer', washer count = #1
Invoice #2, detailid #22, producttype = 'washer', washer count = #2
Invoice #2, detailid #40, producttype = 'washer', washer count = #3


Any help would be appreciated



1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

Hello,

I'm afraid I forgot the "order by" part:

Count:

LOAD *,

     IF(Log_Type = 'REV', IF(ProjNbr = PREVIOUS(ProjNbr), RANGESUM(PEEK('COUNTER'), 1), 1), 0) AS COUNTER

RESIDENT Table

ORDER BY Log_Type, ProjNbr, Z_ID DESC;

Hope we got it.

View solution in original post

21 Replies
Miguel_Angel_Baeyens

Hello,

Create a new field like the following:

If(Previous(producttype) = 'washer', RangeSum(Peek(WasherCount), 1)) AS CountNo


Hope that helps.

Not applicable
Author

Miguel, It kind of works. I need the count to show up on the same row as the record itself. Is this how it works for you?

Miguel_Angel_Baeyens

I'm afraid I'm missing something. The code I wrote is to create a new field when you are LOADing a table (from a excel file, a qvd file or a sql statement), so it will be showed when you create a chart or table with that new field. When do you want to show that count?

Regards

Not applicable
Author

Washercount is the new field I want to create during the load.
When does this field get created?
If(Previous(producttype) = 'washer', RangeSum(Peek(WasherCount), 1)) AS CountNo

Miguel_Angel_Baeyens

Sorry, it should look like

Table: LOAD Invoice, detailid, producttype, If(Previous(producttype) = 'washer', RangeSum(Peek(WasherCount), 1)) AS WasherCount;SQL SELECT Invoice, detailid, producttype FROM YourDatabaseTable;


(in case you are loading from a database)

Hope that helps

Not applicable
Author

Miguel, I tried it. The counts are not landing on the rows with the word "Washer" and it does not seem to recognize the unique Invoice # and InvoiceDetail# combination.

I'm getting Invoice #1, Detail 1, producttype = "bottle", washercount = 1
Invoice #1, Detail 2 producttype = "washer, washercount = 0

Miguel_Angel_Baeyens

Hi,

You probably need an additional if to the code:

Table:LOAD Invoice, detailid, producttype, If(Invoice = Previous(Invoice), If(Previous(producttype) = 'washer', RangeSum(Peek(WasherCount), 1))) AS WasherCount;SQL SELECT Invoice, detailid, producttypeFROM YourDatabaseTable;


Not applicable
Author

I tried this also. The counts are not landing on the "washer" rows and the counts are not accurate at the invoice level. I was thinking something like Aggr(count(if(producttype = 'washer', 1, 0)Invoice) as WasherCount , but this does not work.

Miguel_Angel_Baeyens

Hello,

Now I'm pretty sure I'm missing something. Please attach the sql statement you are using to load your data into QlikView for further advice, as I don't understand how are you loading your data.

Regards.