Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
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!

15 Replies
sunny_talwar

That makes much more sense now.... What do you want the output to look like when there is duplicate Ranking?

PLANRANKINGASSETSSUPERIOR_ASSETS

Plan A

11000
Plan B2100?
Plan C2100?
Plan D3100?

What should the output look like here?

arturomiquelveyrat
Partner - Contributor III
Partner - Contributor III
Author

Great!

Since SUPERIOR_ASSETS is the sum of the ASSETS of plans with higher ranking than the given record, it should look like this:

PLANRANKINGASSETSSUPERIOR_ASSETS

Plan A

11000
Plan B2100100
Plan C2100100
Plan D3100300

Thanks!

sunny_talwar

Try this

Aggr(If(RANKING = Above(TOTAL RANKING), Above(TOTAL RangeSum(Above(TOTAL Sum(ASSETS), 1, RowNo(TOTAL)))), RangeSum(Above(TOTAL Sum(ASSETS), 1, RowNo(TOTAL)))),(RANKING,(NUMERIC)), PLAN)


Capture.PNG

arturomiquelveyrat
Partner - Contributor III
Partner - Contributor III
Author

You're right, it works! Very nice job

Thanks!

arturomiquelveyrat
Partner - Contributor III
Partner - Contributor III
Author

I've just realised that, if you select a record in the table, your solution doesn't work anymore since the result goes to 0.

Do you think it's possible to solve this? I guess that, as long as inter-register functions like Above() are used, the solution will fail when some selection is made on the table.

Thanks!

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

     )