# QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld 2023, a live, in-person thrill ride. Save \$300 before February 6: REGISTER NOW!
cancel
Showing results for
Did you mean:
Contributor III

## 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

the pivot table I need is this one:

1 Solution

Accepted Solutions
MVP

May be this?

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

10 Replies
MVP

Your raw data looks like the 1st screenshot??

Contributor III
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

MVP

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

Contributor III
Author

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

Regards

MVP

Something like this?

Contributor III
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?

MVP

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?

Contributor III
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.

Regards

MVP

May be this?

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

Community Browser