7 Replies Latest reply: Jul 11, 2017 11:21 AM by Onno van Knotsenburg

# Using max function inside a sum

Hello,

I'm attempting to use a max function inside a sum that is multiplying 3 values together in a measure in Qlik Sense, but I am unable to get it to work.  Here is a sample.  The max value is a percentage.  Any help is appreciated.

SUM({<ASSET_TYPE-={'Common Stock','PE Direct Investments','Policy Loan'}>}

(Max([Pref_Pre_Tax_Cap_Chg])) * ([BOOK_VALUE] * [FX_RATE]))

Kim

• ###### Re: Using max function inside a sum

Hi Kim,

It is difficult to say without seeing the initial data and the desired result. Which chart is used? Are there any dimensions? Maybe there is an opportunity to share QVF?

Regards,

Andrey

• ###### Re: Using max function inside a sum

Hi,

have you tried like below?, Thanks

Max(SUM({<ASSET_TYPE-={'Common Stock','PE Direct Investments','Policy Loan'}>} [Pref_Pre_Tax_Cap_Chg] * ([BOOK_VALUE] * [FX_RATE])))

• ###### Re: Using max function inside a sum

Hi Kimberly,

maybe

SUM({<ASSET_TYPE-={'Common Stock','PE Direct Investments','Policy Loan'}>}

(Max(TOTAL <Dimension> [Pref_Pre_Tax_Cap_Chg])) * ([BOOK_VALUE] * [FX_RATE]))

Regards,

Antonio

• ###### Re: Using max function inside a sum

Hi, try the below where the [Pref_Pre_Tax_Cap_Chg] max is selected in the set analysis instead which should work. This only includes the lines where [Pref_Pre_Tax_Cap_Chg] is the max number. If you are looking to sum all lines with the max value of [Pref_Pre_Tax_Cap_Chg] I would have put it in a variable in the script and then used the variable for the calculation.

SUM({<ASSET_TYPE-={'Common Stock','PE Direct Investments','Policy Loan'}, [Pref_Pre_Tax_Cap_Chg] = {\$(=Max([Pref_Pre_Tax_Cap_Chg]))}>} [Pref_Pre_Tax_Cap_Chg] * ([BOOK_VALUE] * [FX_RATE]))

• ###### Re: Using max function inside a sum

Hello Kimberly,

you cannot nest aggregation functions in a easy way as in your example. Based on what you need to achieve you can go with set analysis (as niclaz79 suggests) or use Aggr() function to nest aggregations.

If you only want to consider those values of Pref_Pre_Tax_Cap_Chg which are equal to Max(Pref_Pre_Tax_Cap_Chg), then you can go with set analysis. On the other hand, you want to consider all values and Max(Pref_Pre_Tax_Cap_Chg) depends on dimension values (rows of your table/chart), then you need to use Aggr(). Your expression might look something like this:

SUM({<ASSET_TYPE-={'Common Stock','PE Direct Investments','Policy Loan'}>} Aggr(

(Max([Pref_Pre_Tax_Cap_Chg])) * ([BOOK_VALUE] * [FX_RATE]), Dim1, Dim2))

Dim1 and Dim2 beeing your chart dimensions.

Good luck!

J

• ###### Re: Using max function inside a sum

Thank you for the guidance!  The Aggr function is returning what I expect.

Kim