Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
dimak123
Partner - Contributor III
Partner - Contributor III

Count Quantity for invoice

Good day,

need some help with aggregations:

I want to show a list of clients and to see how many invoices(just count) contained only one item, 2 items, 3 items and 4 according to quantity field.

this is my data:

  

CustomerIdInvoiceIdInvoiceLineItemIdQuantity
10023701390082_INV1106920162
10023701390082_INV2106920161
10023701390083_INV3106920162
10023701390083_INV6106920162
10023701390084_INV7106920162
10023701390084_INV8106920162
10008301390090_INV1102810044
10008301390090_INV2106920161
10008301390091_INV3102810042
10008301390091_INV4102810042
10008301390092_INV5102810041
10008301390092_INV6102810044
10008301390093_INV7102810044
10023701390089_INV1106920161

this what i am trying to get:

      

CustomerId1 item for Invoice2 items for Invoice3 items for Invoice4 items for Invoice5 and more
1002371 12
100083 22

thanks a head

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Then use CustomerID as dimension and 5 expressions:

=Count({<InvoiceId = {"=Sum(Quantity)=1"}>} DISTINCT InvoiceId)

=Count({<InvoiceId = {"=Sum(Quantity)=2"}>} DISTINCT InvoiceId)

=Count({<InvoiceId = {"=Sum(Quantity)=3"}>} DISTINCT InvoiceId)

=Count({<InvoiceId = {"=Sum(Quantity)=4"}>} DISTINCT InvoiceId)

=Count({<InvoiceId = {"=Sum(Quantity)>=5"}>} DISTINCT InvoiceId)

View solution in original post

11 Replies
swuehl
MVP
MVP

Maybe something like this:

Two dimensions:

CustomerId

=Aggr( Sum(Quantity),  InvoiceId)

and one expression:

=Count(DISTINCT InvoiceId)

If you are using a pivot table chart, you can pivot the second dimension to the top.

dimak123
Partner - Contributor III
Partner - Contributor III
Author

i need to show only one dimension

swuehl
MVP
MVP

Then use CustomerID as dimension and 5 expressions:

=Count({<InvoiceId = {"=Sum(Quantity)=1"}>} DISTINCT InvoiceId)

=Count({<InvoiceId = {"=Sum(Quantity)=2"}>} DISTINCT InvoiceId)

=Count({<InvoiceId = {"=Sum(Quantity)=3"}>} DISTINCT InvoiceId)

=Count({<InvoiceId = {"=Sum(Quantity)=4"}>} DISTINCT InvoiceId)

=Count({<InvoiceId = {"=Sum(Quantity)>=5"}>} DISTINCT InvoiceId)

dimak123
Partner - Contributor III
Partner - Contributor III
Author

thank you

wizardo
Creator III
Creator III

Hi,

Coming late to the party but still,

in this method its hard coded, so if you have some invocies with 6 items or your max is 4?? you'll have to manualy add or remove expressions

why not use a pivot with CustomerId and Quantity (Quantity on top) as dimensions

and =Count(DISTINCT InvoiceId) as expression?

then it will be dynamic

Daniel

swuehl
MVP
MVP

Daniel,

I think the OP wants to have the aggregated quantitiy per invoice, so you would need a calculated Dimension (or perform the aggregation in the script).

Then you could reuse my first suggested solution in the very first answer.

wizardo
Creator III
Creator III

hmm,

i understood somthing diffrent i think.

in the oroignal post the OP states:

how many invoices(just count) contained only one item, 2 items, 3 items and 4 according to quantity field


so for example if i take customer 100237 it has 2 invoces :01390082_INV and 01390089_INV (both have 2 item according to quantity field)

so the answer as i see it is 2 (but in your way and also what appears on the original post the answer is 1)

so i admit i don't really understand.

dimak123
Partner - Contributor III
Partner - Contributor III
Author

Daniel

swuehl was right,  i needed to count the invoices (for customer) that had only one item bought (in quantity),two and more.

wizardo
Creator III
Creator III

i still dont get it,

in the example i gave customer 100237 has 2(two invoices) that had only 1 item bought with Quantity of 1

not 1 as you have in your post or in the way swuehl  was counting it

so what am i missing?