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

Count/distinct over time

Hi,

I have got a question regarding counting over certain period of time and was hoping i can get some help from gurus. 

Here is my data:

MaterialNumberCalendarMonthInventoryPositionBucketsViolation
400002019-05-01Above 
400002019-04-01Above 
400002019-03-01Between 
400002019-02-01Between 
400002019-01-01Between 
400002018-12-01Below 
400002018-11-01Below 
400002018-10-01Below 
400002018-09-01Below 
400002018-08-01Below 
400002018-07-01Below 
400002018-06-01Below 
400002018-05-01Below 

 

My issue is for each material number, for each month, I need to count for past 12 months (including current month), how many months have InventoryPositionBuckets as "Below" and put the number in Column "Violation".

For example, for month "2019-05-01", there are 7 months where the inventory position is "Below" between 2019-05-01 and 2018-06-01 (12 months), so the column "Violation" should show 7. it will be great if I can get this done in loading script.

 

Thanks in advance for your help.

 

6 Replies
Lauri
Specialist
Specialist

Hi, if you really need to do it during the load, I think you'll need to use the Peek function but I'm not entirely sure how. And if you have millions of rows, it'll take a while.

Another option is to create an AsOf table and run the calculation in a table or chart on the front end.

https://community.qlik.com/t5/Qlik-Design-Blog/The-As-Of-Table/ba-p/1466130

This works quite well, and gives you more flexibility to change your parameters without reloading.

NZFei
Partner - Specialist
Partner - Specialist

What if you don't have 12 months history?

For example let's say your data start month is 2018-05-01, for the month 2018-06-01, are you going to count only two months 2018-05-01 and 2018-06-01?

Frank_Fu
Contributor
Contributor
Author

Thanks Laurischarf, will try the AsOfTable option, much appreciated. 

Frank_Fu
Contributor
Contributor
Author

Thanks Xufei, yes if there are only 2 months for any month, will need to count only 2 months. your help is much appreciated. 

Channa
Specialist III
Specialist III

how can you say 7 "below" for 

 

400002018-05-01

 

what is the logic

Channa
Frank_Fu
Contributor
Contributor
Author

Hi Channa, for the month of "2018-05-01" the number should  show  1, as only one month (the month of "2018-05-01" itself) has status of Below, as there is no more previous month in the sample shown. Thanks.