15 Replies Latest reply: Jan 24, 2018 6:10 AM by Marco Dalla Pozza

# Rangesum question

Hi Guys,

I've got a rangesum function in a pivot table which I can't make it work as I need.

This is the formula I'm using, it works fine till i keep CalendarYear dimension out of the pivot table, once I put it inside the pivot, the  rolling is interrupted at any new calendar year:

The January yellow highlighted value should be 47 instead , just as in the following screen shot, with no calendar year

• ###### Re: Rangesum question

Use the total qualifier:

RangeSum( total <expression> )

Above( total <expression> )

HIC

• ###### Re: Rangesum question

Hi Henric -

I have never seen this syntax before. I have seen TOTAL within Above() function, but never seen RangeSum() with TOTAL. Also, TOTAL within Above() doesn't really allow to use field names between <>. But it seems that RangeSum() does. Do you have a blog where we can read more about this?

Thanks,

Sunny

• ###### Re: Rangesum question

I forgot to paste the formula I'm using:

rangesum( above( sum(PurchasePlanQuantity),0,RowNo()+12) )-(rangesum( above( sum(ShippedQty),0,RowNo()+12) )+rangesum( above( sum(WhStockQty),0,RowNo()+12) ))

• ###### Re: Rangesum question

Try

If(

Year=Above(total Year),

Rangesum(Above( total [Po-Consolidated] ) , Sum(PurchasePlanQuantity), -Sum(ShippedQty), -Sum(WhStockQty) ),

RangeSum( Sum(PurchasePlanQuantity), -Sum(ShippedQty), -Sum(WhStockQty))

)

• ###### Re: Rangesum question

Hi Enric, awesome script but it's still giving me what I've got already. The range sum of the Calendar Year dimension, I'm trying on the other hand to include the above calendar year dimension into the current calendar year dimension.

The 29 units to which the arrow is pointing should be 49 instead

• ###### Re: Rangesum question

OK, then it's just a matter of moving the condition to the dimension above Year. Try

If( ColorCode=Above(total ColorCode), ...

HIC

• ###### Re: Rangesum question

I'll give it a try right away

• ###### Re: Rangesum question

Hi Eric, close but not yet. Now the first row of the new dimension is correct, but from the 2nd row on, still the rolling is only taking into consideration current dimension figures:

see:

the February testmsr value should be 89 instead: 49 testmsr value from January + 40 Po units in Febrary-0 Shd in February - 0 WhStockQty in February. I have tried to adapt your script but I didn't make it

• ###### Re: Rangesum question

I assume that the column TestMsr is the one that we're looking at. But since you changed the name of the column, you need to change this in the expression to reflect that.

The expression

Rangesum(Above( total [Po-Consolidated] ) , X )

will take the value of Po-Consolidated from the line above, and add X. But now you instead want the value of TestMsr from the line above.

So, then you need to change the expression to

If(

ColorCode=Above(total ColorCode),

Rangesum(Above( total [TestMsr] ) , Sum(PurchasePlanQuantity), -Sum(ShippedQty), -Sum(WhStockQty) ),

RangeSum( Sum(PurchasePlanQuantity), -Sum(ShippedQty), -Sum(WhStockQty))

)

HIC

• ###### Re: Rangesum question

My bad. Thanks for the tip and the explanation as well, you've been a great help

• ###### Re: Rangesum question

Hi Henric, thanks for your answer, I tried and put a total in the editor, but qlik doesn't allow the total predicate

• ###### Re: Rangesum question

This is what confuses me... I have never seen TOTAL within RangeSum, but if Henric has mentioned about this, I would think that we are probably missing something.

• ###### Re: Rangesum question

Sunny

My bad. Temporary brain drop... The total qualifier should of course be in the Above() function.

Also, it won't work with field specifiers after the total qualifier. So the work around must be a conditional evaluation like

If(Year=Above(total Year),Above(total Sum(Sales)),0)

HIC

• ###### Re: Rangesum question

Never thought of using this work around, this is amazing. Thanks for sharing this.

Best,

Sunny

• ###### Re: Rangesum question

Fantastic HIC. Thanks for sharing this.