Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello, I have the below table for which I was initially trying to calculate rolling 12 month sum of sales and display at month level.
Month | grade | sale |
1 | A | 10 |
1 | B | 20 |
1 | C | 30 |
2 | A | 10 |
2 | B | 20 |
2 | C | 30 |
3 | A | 10 |
3 | B | 20 |
3 | C | 30 |
4 | A | 10 |
4 | B | 20 |
4 | C | 30 |
5 | A | 10 |
5 | B | 20 |
5 | C | 30 |
6 | A | 10 |
6 | B | 20 |
6 | C | 30 |
7 | A | 10 |
7 | B | 20 |
7 | C | 30 |
8 | A | 10 |
8 | B | 20 |
8 | C | 30 |
9 | A | 10 |
9 | B | 20 |
9 | C | 30 |
10 | A | 10 |
10 | B | 20 |
10 | C | 30 |
11 | A | 10 |
11 | B | 20 |
11 | C | 30 |
12 | A | 10 |
12 | B | 20 |
12 | C | 30 |
Initial output: I got this part correct.
Month | sum(aggr(rangesum(above( total sum({<Month=>}sale),0,12)),Month)) |
1 | 60 |
2 | 120 |
3 | 180 |
4 | 240 |
5 | 300 |
6 | 360 |
7 | 420 |
8 | 480 |
9 | 540 |
10 | 600 |
11 | 660 |
12 | 720 |
But when I pull the second dimension into the pivot table, I am not seeing expected results for Rolling 12 months values for the combination of these dimensions.
Month | grade | sum(aggr(rangesum(above(sum(sale),0,12)),Month,grade)) |
1 | A | 10 |
1 | B | 30 |
1 | C | 60 |
2 | A | 10 |
2 | B | 30 |
2 | C | 60 |
3 | A | 10 |
3 | B | 30 |
3 | C | 60 |
4 | A | 10 |
4 | B | 30 |
4 | C | 60 |
5 | A | 10 |
5 | B | 30 |
5 | C | 60 |
6 | A | 10 |
6 | B | 30 |
6 | C | 60 |
7 | A | 10 |
7 | B | 30 |
7 | C | 60 |
8 | A | 10 |
8 | B | 30 |
8 | C | 60 |
9 | A | 10 |
9 | B | 30 |
9 | C | 60 |
10 | A | 10 |
10 | B | 30 |
10 | C | 60 |
11 | A | 10 |
11 | B | 30 |
11 | C | 60 |
12 | A | 10 |
12 | B | 30 |
12 | C | 60 |
I expect to see:
Month | grade | sum(aggr(rangesum(above(sum(sale),0,12)),Month,grade)) |
1 | A | 10 |
1 | B | 20 |
1 | C | 30 |
2 | A | 20 |
2 | B | 40 |
2 | C | 60 |
3 | A | 30 |
3 | B | 60 |
3 | C | 90 |
Any suggestions. I am not sure if I am doing this right. maybe above() is not the right function here.
I could do it longitudinal like this, which would give right results, but there are many such combination of dimensions in the actual data to do it this way.
Month | sum(aggr(rangesum(above( total sum({<Month=,grade={'A'}>}sale),0,12)),Month)) | sum(aggr(rangesum(above( total sum({<Month=,grade={'B'}>}sale),0,12)),Month)) | sum(aggr(rangesum(above( total sum({<Month=,grade={'C'}>}sale),0,12)),Month)) |
1 | 10 | 20 | 30 |
2 | 20 | 40 | 60 |
3 | 30 | 60 | 90 |
4 | 40 | 80 | 120 |
5 | 50 | 100 | 150 |
6 | 60 | 120 | 180 |
7 | 70 | 140 | 210 |
8 | 80 | 160 | 240 |
9 | 90 | 180 | 270 |
10 | 100 | 200 | 300 |
11 | 110 | 220 | 330 |
12 | 120 | 240 | 360 |
I have these two tables:
LINE_ITEMS1:
Load * Inline [
Account, grade, range
1, A, 10-20
2, A, 20-30
3, A, 10-20
4, B, 30-40
5, B, 30-40
];
LINE_ITEMS2:
LOAD * Inline [
Month, Account, loss
1, 1, 0
2, 1, 0
3, 1, 0
4, 1, 100
5, 1, 0
1, 2, 0
2, 2, 0
3, 2, 0
4, 2, 0
5, 2, 0
6, 2, 0
7, 2, 0
8, 2, 0
9, 2, 0
10, 2, 22
11, 2, 0
12, 2, 0
1, 3, 0
2, 3, 0
3, 3, 0
4, 3, 0
5, 3, 0
6, 3, 0
7, 3, 0
8, 3, 0
9, 3, 0
10, 3, 50
11, 3, 0
12, 3, 0
1, 4, 0
2, 4, 0
3, 4, 0
4, 4, 0
5, 4, 0
6, 4, 0
7, 4, 0
8, 4, 0
9, 4, 0
10, 4, 11
11, 4, 0
12, 4, 0
1, 5, 0
2, 5, 0
3, 5, 0
4, 5, 0
5, 5, 0
6, 5, 0
7, 5, 0
8, 5, 0
9, 5, 0
10, 5, 200
11, 5, 0
12, 5, 0
];
I want to calculate rolling 12 month loss for each grade and range combination for each month.
desired result:
Month | grade | range | rolling_12_loss |
1 | A | 10-20 | 0 |
1 | A | 20-30 | 0 |
1 | B | 30-40 | 0 |
2 | A | 10-20 | 0 |
2 | A | 20-30 | 0 |
2 | B | 30-40 | 0 |
3 | A | 10-20 | 0 |
3 | A | 20-30 | 0 |
3 | B | 30-40 | 0 |
4 | A | 10-20 | 100 |
4 | A | 20-30 | 0 |
4 | B | 30-40 | 0 |
5 | A | 10-20 | 0 |
5 | A | 20-30 | 0 |
5 | B | 30-40 | 0 |
6 | A | 10-20 | 0 |
6 | A | 20-30 | 0 |
6 | B | 30-40 | 0 |
7 | A | 10-20 | 0 |
7 | A | 20-30 | 0 |
7 | B | 30-40 | 0 |
8 | A | 10-20 | 0 |
8 | A | 20-30 | 0 |
8 | B | 30-40 | 0 |
9 | A | 10-20 | 0 |
9 | A | 20-30 | 0 |
9 | B | 30-40 | 0 |
10 | A | 10-20 | 150 |
10 | A | 20-30 | 22 |
10 | B | 30-40 | 211 |
11 | A | 10-20 | 150 |
11 | A | 20-30 | 22 |
11 | B | 30-40 | 211 |
12 | A | 10-20 | 150 |
12 | A | 20-30 | 22 |
12 | B | 30-40 | 211 |
any suggestions?
Thanks
I didn't get the logic, how come 12 A and 12 B are populated, while others are not. Please explain the logic.
Regards
Pratyush
I am sorry , yes 5 - A - 10-20, 6 - A - 10-20 .... should also be populated.