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

Sum all records with some field less than the given record

A table has the following fields: PLAN, RANKING and ASSETS. We need to calculate SUPERIOR_ASSETS, which is the sum of the assets of the plans with a higher ranking:

PLANRANKINGASSETSSUPERIOR_ASSETS

Plan A

11000
Plan B2100100
Plan C3100200
Plan D4100300

The expression I've built so far is:

Aggr(
Sum(
{<
 
RANKING = {"< X"}
>}
Total
ASSETS
),
PLAN
)

The question is how to substitute the "X" with a variable / expression that takes the value of the RANKING in each plan.


I've attached a QlikView and an Excel file to make testing solutions easier.

Note: the table object will not contain the RANKING, so functions like Column() or Top() will not be useful.

Thank you!

1 Solution

Accepted Solutions
arturomiquelveyrat
Partner - Contributor III
Partner - Contributor III
Author

I've fixed it:

Just add {1} to the Sum()'s in your code to ensure all records are selected:

Aggr(

     If(RANKING = Above(TOTAL RANKING),

          Above(TOTAL RangeSum(Above(TOTAL Sum({1} ASSETS), 1, RowNo(TOTAL)))),

          RangeSum(Above(TOTAL Sum({1} ASSETS), 1, RowNo(TOTAL)))

          ),

     (RANKING,(NUMERIC)),

     PLAN

     )

View solution in original post

15 Replies
sunny_talwar

How is Ranking determined if it is not given?

arturomiquelveyrat
Partner - Contributor III
Partner - Contributor III
Author

Hi Sunny,

The field RANKING is in one of the tables of the data model, but will not appear in the table object.

sunny_talwar

But you said it won't be available in the dashboard, how are we suppose to know what the ranking is, if it is not given? Is there a way to derive this using other available fields?

effinty2112
Master
Master

Hi Arturo,

Maybe:

PLAN Rangesum(above(TOTAL Sum(ASSETS),1,RowNo(TOTAL)))
Plan A0
Plan B100
Plan C200
Plan D

300

Regards

Andrew

arturomiquelveyrat
Partner - Contributor III
Partner - Contributor III
Author

Hi Andrew,

Thanks, but this only works if the  table is ordered by RANKING.

effinty2112
Master
Master

Hi Arturo,

try:

PLAN Aggr(Rangesum(above(TOTAL Sum(ASSETS),1,RowNo(TOTAL))),(RANKING,NUMERIC,ASCENDING))
Plan D300
Plan C200
Plan B100
Plan A0

PLAN Aggr(Rangesum(above(TOTAL Sum(ASSETS),1,RowNo(TOTAL))),(RANKING,NUMERIC,ASCENDING))
Plan C200
Plan A0
Plan D300
Plan B100

Cheers

Andrew

arturomiquelveyrat
Partner - Contributor III
Partner - Contributor III
Author

Thanks Andrew! This is very helpful.

However, I guess this will fail if 2 records happen to have the same RANKING.

sunny_talwar

I am just not sure how this is going to work without the RANKING field being available? Are you saying that RANKING is now available?

arturomiquelveyrat
Partner - Contributor III
Partner - Contributor III
Author

Hi Sunny,

It seems I didn't make myself clear enough. The field RANKING is available in the dashboard. All I've just wanted to state is that RANKING is not going to be in the table object I'm trying to create.