Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
johnnyjohn
Creator
Creator

Sum for previous month with month as dimension

Say I have the following table where month is a dimension. Sum data is calculated with Sum(data)

MonthSum data
01/07/20191
01/08/20192
01/09/20193
01/10/20194
01/11/20195

 

How can I calculate the sum for the previous month, i.e.

MonthSum dataSum data previous month
01/07/20191-
01/08/201921
01/09/201932
01/10/201943
01/11/201954
Labels (1)
10 Replies
tresesco
MVP
MVP

Try in chart second expression like:

=Above( Sum(Sales))

johnnyjohn
Creator
Creator
Author

Hi, thanks a lot for your reply.

I thought I would make the question as simple as possible but it seems to have been a mistake, I wasn't able to fully convey what I want to do.

The data I have also contains a second dimension, "saleperson". What I am trying to accomplish is calculate how much John did this month vs how he did in the previous month, same for Mike.

I can't seem to be able to use above() for this, since it return the other sales person record. Any ideas how what I am trying to do can be done?

MonthSalespersonSum data% increase
01/07/2019John10-
01/07/2019Mike5-
01/08/2019John100900% (from 10 to 100)
01/08/2019Mike20300% (from 5 to 20)
tresesco
MVP
MVP

To achieve similar output in chart - it would be easier if you could change the chart construct a bit. Put Salesperson as dimension (rows) and bring the months in column, then you could use before() like above() to get the variance. Otherwise, you could take a script-route to calculate it.

johnnyjohn
Creator
Creator
Author

I am not sure I understand how I can put the months in columns without it aggregating aggregating all the sales numbers for a single Saleperson over the entire months.

However, I simply want to get the number I've explained above (month of month % difference of sales for a single saleperson). I may want to plot this in a graph, and not in a table. How would you approach this using scripting?

Thanks

tresesco
MVP
MVP

If you have more than two months data, how would you like the output to be? 

johnnyjohn
Creator
Creator
Author

The value I am trying to calculate is:

John's value for month M = % difference (Sum of sales for John in Month M, Sum of sales for John in Month M - 1)

Mikes's value for month M = % difference (Sum of sales for Mike in Month M, Sum of sales for Mike in Month M - 1)

So the output could be, for instance, a bar chart, with the dimension being the month, and for each month M two bars are shown, one for Mikes's value for month M and one for John's value for month M.

Or we could imagine a line chart, where dimensions (x axis), is again month, or time, and each line represents the salesperson's % difference of the month vs the previous month.

tresesco
MVP
MVP

Why two bars always, number or salesperson also could be many right?

johnnyjohn
Creator
Creator
Author

Yes correct. I said two in the context of the example with our two salesperson, but there will be more than two in reality.

ruparaja
Partner - Contributor
Partner - Contributor

Hi , Have tried in Backend please find the below script

date_values:
Load
*,
peek("Sum data") as previous_month_record;

LOAD
"Month",
"Sum data"
FROM [lib://data/date_values.xlsx]
(ooxml, embedded labels, table is Sheet1);
Out put: