# New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
IMPORTANT: Upcoming LEF Database Maintenance, Oct. 3rd - SEE DETAILS
cancel
Showing results for
Did you mean:
Highlighted
Partner

## Rangesum based on flag condition

Hi Qliker,

I was facing a challenge to perform the calculation in the front end.

The cumulation need to be done based on the flag as a condition,

below is the example,

 Days Flag Value Output Calculation 1 1 5 0 2 2 10 0 3 3 10 0 4 1 10 15 (10+15) Cumulating all records above having flag 1 5 2 10 20 (10+10) Cumulating all records above having flag 2 6 3 6 16 (10+6) Cumulating all records above having flag 3 7 1 4 19 (10+15+4) Cumulating all records above having flag 1 8 2 6 26 (10+10+6) Cumulating all records above having flag 2 9 3 8 24 (10+6+8) Cumulating all records above having flag 3

The requirement is such a way, the calculation has cannot be done in the backend.

Mohan

Labels (2)

• ### rangesum

9 Replies
Highlighted
Partner

I have attached the example file in the attachment.

Highlighted
MVP

Try this expression

``Aggr(RangeSum(Above(Value, 0, RowNo())), Flag, Days)``
Highlighted
MVP

Or this if Days are not sorted in the script

``Aggr(RangeSum(Above(Value, 0, RowNo())), Flag, (Days, (NUMERIC)))``
Highlighted
Partner

Hi Sunny,

The expression is working perfectly, in the sample file shared. I tried to apply the same in my file, it bit tricky for me to understand the expression in what way it goes wrong.

Please have a look at the attached application, in which I'm working on.

Kindly help..!!

Regards,

Mohan

Highlighted
Partner
Attaching the file
Highlighted
Partner

Hi Sunny,

To be clear on what I'm trying to achieve is to roll up every 20th from the start.

Assuming the fact the person leaves at every 20th day, no. of people leaves creates the vacant for next day (21st Day). Thats the reason why the Flag column is created to rolling down the values every 20 days.

Hope the above logic description is understandable.

Regards,

Mohan

Highlighted
MVP

I am not sure I understand

Highlighted
Partner

As I explained in the header example, I need to accumulate the values of the 3rd record respectively. The expression suggested is working fine in the provided sample file.

When I tried to apply the same in the application(recently attached qvf) in which I'm working on. The expression isn't working correctly as expected.

In the previous reply, I tried to explain the business behind the logic I'm working on. If open the qvf, the patient admitted is the same, for 1st cycle which is 1-20 days, when the next cycle starts, 1st cycle patient moves away and beds occupied by them is assigned to the person comes in 2nd cycle (21-40 days). Likewise, it goes on till the date entered in the data.

Regards,

Mohan

Highlighted
Partner

Hi Sunny,

Is there is any help I can get?