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

How many months a product has been selling for

Imagine the dataset;

ProductMonthSales
AppleJan

$5

AppleFeb$3
AppleMar$4
AppleMar$2
BananaMar$3
BananaApr$3
BananaMay$2
CoconutFeb$10
CoconutMar$3

 

What I'd like to produce in Sense is a table which looks like this;

ProductMonthSalesHow many months sales
AppleJan

$5

1

AppleFeb$32
AppleMar$43
AppleMar$23
BananaMar$31
BananaApr$32
BananaMay$23
CoconutFeb$101
CoconutMar$32

 

Unsure where to start with this.

Thanks for any advice.

1 Reply
stevejoyce
Specialist II
Specialist II

In the front-end, you may be able to just get away with RowNo(), which does a count on your last dimension and resets back to 1 on your 2nd to last.

 

If it's row level in your data model, you can use peek() function, make sure data is sorted correctly like...

tbl:

load *

,if(peek(Product) <> Product and peek(Month) <> Month, 1,  if(peek(Product) = Product and peek(Month) = Month, peek([How many months sales]), if(peek(Product) = Product and peek(Month) <> Month, peek( [How many months sales] ) + 1)))

as [How many months sales]

resident <tbl>

order by Product asc, DateField asc