Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
TPoismans
Partner - Contributor III
Partner - Contributor III

Sum of values higher than rank 20 of a dimension

Hi all

Consider the following data:

CompanyPersonDateTimestampValue
AX1/2/20191/2/2019 7:00:003594
AX1/2/20191/2/2019 7:05:001263
AX1/2/20191/2/2019 7:10:001961
AX1/2/20191/2/2019 7:15:002002
AX1/2/20191/2/2019 7:20:001653
AX1/2/20191/2/2019 7:25:003595
AX1/2/20191/2/2019 7:30:003141
AX1/2/20191/2/2019 7:35:001726
AX1/2/20191/2/2019 7:40:003233
AX1/2/20191/2/2019 7:45:003531
AX1/2/20191/2/2019 7:50:003890
AX1/2/20191/2/2019 7:55:001710
AX1/2/20191/2/2019 8:00:001665
AX1/2/20191/2/2019 8:05:004126
AX1/2/20191/2/2019 8:10:004334
AX1/2/20191/2/2019 8:15:002909
AX1/2/20191/2/2019 8:20:003226
AX1/2/20191/2/2019 8:25:003401
AX1/2/20191/2/2019 8:30:004244
AX1/2/20191/2/2019 8:35:004111
AX1/2/20191/2/2019 8:40:001341
AX1/2/20191/2/2019 8:45:001888
AX1/2/20191/2/2019 8:50:001989

 

What I want to achieve is the following:

CompanyPersonDate# linesValue of lines > 20
AX1/2/2019235218

The last two colums are a measure. The second measure is what I'm looking for.

If there are more than 20 lines for a person on 1 date, give me the sum of the values of the lines above 20. For the dummy data, that would be: 1341+1888+1989 = 5218.

 

If any more info is needed, please ask and thanks in advance.
Kind regards,

Tim P.

1 Solution

Accepted Solutions
sunny_talwar

That is true, but can you try this out?

If(Count(Timestamp) > 20, Sum(Aggr(If(RowNo() > 20,
-Sum({$<[Tankpost Soort]={"Leveren","Ledigen","Bunkeren"},[Tankpost Aantal Check]={1}>} [Tankpost Aantal])
), Company, Person, Date, Timestamp)))

If this doesn't work and you are using QlikView 12 or above, you can try this

If(Count(Timestamp) > 20, Sum(Aggr(If(RowNo() > 20,
-Sum({$<[Tankpost Soort]={"Leveren","Ledigen","Bunkeren"},[Tankpost Aantal Check]={1}>} [Tankpost Aantal])
), Company, Person, Date, (Timestamp, (NUMERIC)))))

View solution in original post

6 Replies
sunny_talwar

If your data is sorted correctly by the ascending order by timestamp in the script, then you can try this

If(Count(Timestamp) > 20, Sum(Aggr(If(RowNo() > 20, Value), Company, Person, Date, Timestamp)))
TPoismans
Partner - Contributor III
Partner - Contributor III
Author

The value is already a calculated value with set analysis. So RowNo() sadly won't work. 
Should've mentioned that, my bad.

 

Regards,
Tim P.

sunny_talwar

What is the expression for Value? It might still work...

TPoismans
Partner - Contributor III
Partner - Contributor III
Author

The expression for the value is:

-Sum({$<[Tankpost Soort]={"Leveren","Ledigen","Bunkeren"},[Tankpost Aantal Check]={1}>} [Tankpost Aantal])

But that won't help much if can't try it with real data, which I'm not allowed to hand out.


Kind regards,
Tim P.

sunny_talwar

That is true, but can you try this out?

If(Count(Timestamp) > 20, Sum(Aggr(If(RowNo() > 20,
-Sum({$<[Tankpost Soort]={"Leveren","Ledigen","Bunkeren"},[Tankpost Aantal Check]={1}>} [Tankpost Aantal])
), Company, Person, Date, Timestamp)))

If this doesn't work and you are using QlikView 12 or above, you can try this

If(Count(Timestamp) > 20, Sum(Aggr(If(RowNo() > 20,
-Sum({$<[Tankpost Soort]={"Leveren","Ledigen","Bunkeren"},[Tankpost Aantal Check]={1}>} [Tankpost Aantal])
), Company, Person, Date, (Timestamp, (NUMERIC)))))
TPoismans
Partner - Contributor III
Partner - Contributor III
Author

First measure worked perfectly, thanks!