Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Diinkant
Contributor III
Contributor III

Cumulative Sum across periods with reset

Hi,

I am trying to create a cumulative sum across various periods within a financial year but running into a few issues. Image of my data set below.

Diinkant_0-1735253406157.png

In the above image you can see the activity is the same as the cumulative sum, but that shouldn't be the case.

The formula I have tried
- RangeSum(
Above(
Sum({
<PeriodID = {">=$(vLastYearStartPeriod)<=$(vLastYearEndPeriod)"}>
} [Transaction Amount]),
0,
RowNo()
)
)

Keep in mind that another dimension is called account code. So, when it goes into a new account code, the cumulative sum should reset to whatever the activity number is. 

 

Labels (1)
7 Replies
pallavi_96
Partner - Creator
Partner - Creator

Hi @Diinkant 

Could you please share the dataset that includes the AccountCode for further clarification?

Diinkant
Contributor III
Contributor III
Author

Hi @pallavi_96 

The accountcode would like this (with the ideal outcome):

AccountCode | PeriodID | Activity | Cumulative | FiscalYear

1110.000 | 2701| 10 | 10 | 2022-2023

1110.000 | 2702 | 20 | 30 | 2022-2023

1120.000 | 2701 | 10 | 10 | 2022-2023

1120.000 | 2702 | 30 | 40 | 2022-2023

1110.000 | 2801 | 20 | 20 | 2023-2024

The cumulative sum should be a sum for that account code across that fiscal year but break down per period.

pallavi_96
Partner - Creator
Partner - Creator

HI @Diinkant 

Are you expecting the output below for your query?

pallavi_96_0-1735535983106.png

If yes, please use the following expression

sum(Aggr(RangeSum(Above(sum(Activity), 0, RowNo())), AccountCode,PeriodID))

Diinkant
Contributor III
Contributor III
Author

Thanks for that recommendation but that doesn't work either.

 

For Example, here are the results with the last column being the formula.

Diinkant_0-1735591947518.png

 

pallavi_96
Partner - Creator
Partner - Creator

Hi @Diinkant ,

I used the same formula on your dataset, and it gave me the correct cumulative values for account code 1210.

pallavi_96_0-1735794219488.png

 

Diinkant
Contributor III
Contributor III
Author

Hi @pallavi_96 ,

 

Thanks, I have tried it with this dataset 
Test:
Load * Inline [
Transaction Date,Account Code,FiscalYear,PeriodID,Transaction Amount
9-10-2022,1120.000,2022-2023,2701,100
10-10-2022,1120.000,2022-2023,2701,150
11-10-2022,1120.000,2022-2023,2701,200
9-11-2022,1120.000,2022-2023,2702,200
10-11-2022,1120.000,2022-2023,2702,300
11-11-2022,1120.000,2022-2023,2702,400
9-12-2022,1120.000,2022-2023,2703,300
10-12-2023,1120.000,2023-2024,2801,250
11-12-2023,1120.000,2023-2024,2802,350
1-10-2022,1121.000,2022-2023,2701,150
2-10-2022,1121.000,2022-2023,2701,250
3-10-2022,1121.000,2022-2023,2701,350
1-11-2022,1121.000,2022-2023,2702,150
1-11-2022,1121.000,2022-2023,2702,250
2-12-2022,1121.000,2022-2023,2702,50
9-12-2023,1121.000,2023-2024,2801,100
];

 

It works.

So, there must be something with the way I am loading my actual data as it works with test data.

Do I need to order my data in a specific way for it to work within the load script like I have with the test data. This is my load script:

Transactions:
[Account Code],
[Branch Code],
[Department Code],
PeriodID,
[Transaction Amount],
Month(Date(Date#([Transaction Date],'YYYY-MM-DD'),'DD/MM/YYYY')) as Month,
MonthName(Date(Date#([Transaction Date],'YYYY-MM-DD'),'DD/MM/YYYY')) as MonthName,
Year(Date(Date#([Transaction Date],'YYYY-MM-DD'),'DD/MM/YYYY')) as Year,
YearName(Date(Date#([Transaction Date],'YYYY-MM-DD'),'DD/MM/YYYY'), 0, 7) as FiscalYear,
[Transaction Date]

From [Transactions.qvd] (qvd);

pallavi_96
Partner - Creator
Partner - Creator

Hi @Diinkant,

Please try to sort the 'Account Code' column in the table.