Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Sum of Invoices of a month where first date is in between that month and the two previous

Hi everyone, hope someone can help me cause I've been trying to achieve this for days and I couldn't get it.

What I'm trying to get is a pivot table with two dimensions; Year and Month. The expression I need is the sum of the invoices amount of all the customers which first date of invoice is between the last day of the month of the dimension and the first day of the two previous months of that value of the dimension. So for the Nov-2016 I need all the invoices in November which first Invoice Date is between 01/09/2016-30/11/2016.

For example if I have the following values

Captura.JPG

the pivot table I need is this one:

Captura.JPG

Thanks in advance for your time.

1 Solution

Accepted Solutions
sunny_talwar

May be this?

=Sum(Aggr(If(Min(TOTAL <Customer> Date) >= AddMonths(MakeDate(Year, Month), -2), Sum(Amount)), Year, Month, Customer))

Capture.PNG

View solution in original post

10 Replies
sunny_talwar

Your raw data looks like the 1st screenshot??

Anonymous
Not applicable
Author

Sorry Sunny, I don´t understand pretty well what you're asking. In the 1st screenshot e.g. the value of 500 means the total sum of the invoices for the Customer A in the month of sep-2016. They are example values. Is that what you meant?

Regards

sunny_talwar

What I am trying to understand is how does your raw data looks like? Is it like this?

Capture.PNG

Anonymous
Not applicable
Author

     Ah ok, I get it. Excuse me again. No, they would be like this. The bold date means the first Invoice Date

Captura.JPG

Regards

sunny_talwar

Something like this?

Capture.PNG

Anonymous
Not applicable
Author

Yeah!! That's is what I'm looking for. I migth be wrong but I think I must use the P function to select all the customers with the first date in that period and get the sum of their invoices. What you think?

sunny_talwar

I just used Sum(Amount)... I am not sure I understand your logic related to the first date. Would you mind expanding a little on this?

Anonymous
Not applicable
Author

Ah ok, I see. My fault, I didn't notice the difference between you table and mine. For example, if you take a  look at december in this table, you'll see a total amount of 400. In yours It is 750. That's because i don´t include Customer A and Customer B given the fact that their first invoice date belong to september, and  so they are not in the period of oct-nov-dec. PD.This table has the value of Dec correct.

Captura.JPG

Regards

sunny_talwar

May be this?

=Sum(Aggr(If(Min(TOTAL <Customer> Date) >= AddMonths(MakeDate(Year, Month), -2), Sum(Amount)), Year, Month, Customer))

Capture.PNG