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

filter invoices based on items inside

Hello!

My question is probably easy enough and I hope you don't blame my ignorance 🙂

So, let's suppose that we have a simple table with the following data:

INVOICE NO. ITEM AMOUNT

---------------------------------------------------------------------------------------------------

111 AAA 10

111 BBB 15

222 AAA 5

333 CCC 17

333 BBB 4

444 AAA 3

Now I would like to count all invoices which contain AAA items, but do NOT contain BBB items.

I guess that I maybe have to use aggr() here, but I do not quite realize how to do it.

Thanks in advance!

12 Replies
sathishkumar_go
Partner - Specialist
Partner - Specialist

Hi

use this COUNT(if(Item = 'AAA',Invoice))

-Sathish

Not applicable
Author

Your solution seems obvious, but I think that this way I will count invoice 111 and that would be wrong...

Not applicable
Author

Hi gmanoilov,

Is the data in the same structure as you habe illustrated? Or is the structure a bit different?

Not applicable
Author

Hello!

In fact, the physical tables in the source database are different.

We have a table with the general invoice data (eg. creation date, place of delivery, etc.), then we have another table with the item details (it contains records for all items in all invoices) and we have a third table that contains foreign keys to link the first two tables.

But is this really important?

Not applicable
Author

Hi

Can you load a concatenated string of items for each invoice and then rule invoices out that contain your unwanted items?

Not sure about your requirements but can you use the items count in the invoice and rule out the ones having more than one item?

Regards

Juerg

Not applicable
Author

What I wanted to confirm was whether all the items are stated against an Invoice

eg INVOICE # 111 would have AAA & BBB both written in front of it?

If that is the case then you can use Index function to find the location of required names

Not applicable
Author

Unfortunately I cannot just rule out invoices with more that one item, because I can have invoices with items AAA and CCC (and even DDD and etc.) and they should still be taken into account.

Maybe the concatenation idea would work, but I will be much more happy if it could be done with a simple combination of aggregation and conditional functions in the chart...

Not applicable
Author

Hello Umang!

I am not sure what you mean by "written in front of it", but yes, all items are linked to an invoice using primary and foreign keys in the database. I do not know much about the index function, so I will go and read. (I am not very optimistic, though) Then I will post back my comments.

Best wishes!

Not applicable
Author

Hi,

What I mean to ask is whether your data is in this format ( or can be brought into this format.

INVOICEITEMAMOUNT
111AAA,BBB18
222AAA28
333CCC,BBB13
444AAA

32