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

Count unique values based on value in other fields/columns, on specific time value

Hi,

I have the situation similar to the original posting.
https://community.qlik.com/t5/New-to-QlikView/Count-values-based-on-other-columns-too/m-p/258995

The following expression help to count correctly.

=sum( aggr(count(DISTINCT [Final product batch number]), Year, Month, [Product name]))

Could someone help to explain how the logic works here?

Here is the example of the data to look at.

YearMonthProduct nameraw material  nameFinal product  batch number
20121Product 1Raw material 11
20121Product 1Raw material 21
20121Product 1Raw material 31
20121Product 1Raw material 12
20121Product 1Raw material 22
20121Product 1Raw material 32
20111Product 1Raw material 11
20111Product 1Raw material 21
20111Product 1Raw material 31
20111Product 1Raw material 12
20111Product 1Raw material 22
20111Product 1Raw material 32
20112Product 1Raw material 13
20112Product 1Raw material 23
20112Product 1Raw material 33
20112Product 2Raw material 11
20112Product 2Raw material 21
20112Product 2Raw material 31
20112Product 2Raw material 41
20112Product 2Raw material 51

 

I would also like to have the count of the [Raw material] with certain [Final product batch number] in the most recent month, by [Product name]. 

So, If the [Final product batch number] desired is 1, the result for Product 1 should be 3, as the most recent month is 2012+01, and there are 3 counts of Raw material with the batch number = 1. 

How should the expression be modified to count this? (I know it should be Max(YearMonth) or something like it. I just can't figure out the correct syntax, probably due my lack of understanding on how the original expression works.)

Thanks in advance,

 

Ernest

Labels (2)
1 Solution

Accepted Solutions
y_grynechko
Creator III
Creator III

Hey,

I created additional field in the load: 

Year * 12 + Month as YearMonthNum 

which I use in the calc later on: 

count({<YearMonthNum = {"$(=Max(YearMonthNum))"}, [Final product  batch number] = {'1'}>}[raw material  name])

Capture.PNG

View solution in original post

1 Reply
y_grynechko
Creator III
Creator III

Hey,

I created additional field in the load: 

Year * 12 + Month as YearMonthNum 

which I use in the calc later on: 

count({<YearMonthNum = {"$(=Max(YearMonthNum))"}, [Final product  batch number] = {'1'}>}[raw material  name])

Capture.PNG