Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Nickolay1
Contributor III
Contributor III

Count number of batches based on the latest UD code

Hi All,

Hopefully you can help me here. I need to build a bar chart that will have GR month as X axes and number of batches as bars. Based on the dataset below every month a snapshot is taken. And it contains a history of all the UD codes that batch received. For example if the batch 1 had GR in Nov 23 and received its UD code 0 also in Nov 23, then it received next UD code 60 in Jan 24; in this case if we use the data set below this batch will be counted 2 times in the chart. I wonder how can we ensure that this batch is counted only once based on its latest UD code. 

I tried to use a condition for maximum UD code, but it didn't work: 

({<[UD Code]={"$(=max([UD Code]))"}>}

 

Also Distinct operator doesn't help

 

Nickolay1_0-1716312844253.png

 

Data Month - Year Batch Number GR Date UD Code Usage Decision Date
Nov-2023 1 13/11/23 - -
Dez-2023 1 13/11/23 0 10/11/23
Jan-2024 1 13/11/23 0 10/11/23
Jan-2024 1 13/11/23 60 26/01/24
Feb-2024 1 13/11/23 0 10/11/23
Feb-2024 1 13/11/23 60 26/01/24
Mär-2024 1 13/11/23 0 10/11/23
Mär-2024 1 13/11/23 60 26/01/24
Labels (5)
2 Solutions

Accepted Solutions
BrunPierre
Partner - Master
Partner - Master

It should work like this.

=Count(DISTINCT If( [UD Code] = Aggr(Max(TOTAL <[Data Month - Year]> [UD Code]), [UD Code], [Data Month - Year]), [Batch Number]))

View solution in original post

Chanty4u
MVP
MVP

Try this.count(distinct {<

    [UD Code] = {"$(=max(aggr(max([UD Code]), [Batch ID])))"}

>} [Batch ID

])

View solution in original post

3 Replies
BrunPierre
Partner - Master
Partner - Master

It should work like this.

=Count(DISTINCT If( [UD Code] = Aggr(Max(TOTAL <[Data Month - Year]> [UD Code]), [UD Code], [Data Month - Year]), [Batch Number]))

Chanty4u
MVP
MVP

Try this.count(distinct {<

    [UD Code] = {"$(=max(aggr(max([UD Code]), [Batch ID])))"}

>} [Batch ID

])

Nickolay1
Contributor III
Contributor III
Author

Thanks all! It worked. The key is to use aggregation formula. I also realized that it's better to use combo chart here and create separate measures for each stack.