BAQ-What they don't buy

In a purely general sense, I am looking to find what parts my customers do not buy. I am able to get what they do buy very easily but every time I try to flip it to what they don’t buy I get a zero, which I know is incorrect.

Specifically, I needed to group parts and due ot how things were set up before I came on-board, in testing it was easier to just use the Part Reference since it was not being used. So I created 13 groups and grouped the parts accordingly. Then I have Part–>InvcDtl–>Customer and my BAQ. Display fields are CustId and refCategory. I tried to i use a Sub Query and then in the SubQuery Criteria input Part reference category Not = to any values of Part reference Category subqueryB. Which does not help me at all. Any ideas on what Ia m doing wrong or could do better with this?

Try using not in. There are many ways to do this. I would create a few subquerys first so that you can validate your final query a bit easier.

First subquery will be the list of parts the customer can buy.
Second subquery that shows parts that the customer has bought.

Then write a third top level query that will show items in the first query that are not in the second subquery.

The top level query will look something like this.

select * from FirstSubQueryList
where parts not in (select parts from SecondSubquery)

1 Like

NotBuy.baq (17.4 KB)

Here is a basic BAQ that should get you started. You can add additional filters to exclude inactive parts, non-qty bearing parts, run out parts, etc.

1 Like

@lgraham Thanks for the baq! Been playing with it and is very similar to what i had originally wrote.

@knash I know this is going ot sounds dumb but how do I do the from first subquery part? IS it under the SubQuery criteria? Tried that and wouldn’t let me. So trying to figure out how to invoke that.

If you want upload your BAQ I will update on my end and send back.

1 Like

@knash Figured it out. Thanks for the pic and the reply.

After running this and thinking on it, It struck me that I am using ref categories and not part numbers. And we have multiple part number sin a ref category. Thus the output is skewed a little. I am thinking I would have to add the Ref category to the InvcDtl table. thoughts?

@Banderson Let’s take this one step at a time. That way I don’t confuse myself. LOL!

So, first, I created this. This shows correctly the parts customers have purchased.

I have to group these to keep them from multiplying because I am using the Invcdtl table. It also does this with the orderdtl table as well. But it works out. I have 13 categories and most customers never buy all the categories.

I then create a subquery. This one will show the part ref cat and we will use the first query as a filter for the 2nd. Well, that’s what Ia m trying to do. What I get as the result is blanks for Ref Cat.

show me your display field in your sub-query and your calculated field in the top level.

There are no calculated fields.

The displays are identical.

You either need to make a calculated field that brings in the result from the subquery, or you need to bring the subquery into the top level as a table

It looks like this when you bring it in. However, it will only work with one display field showing. More that one will not work this way.

If I bring the subquerry into the top level, will more than one result be ok? I need the custnum and the part.refcat they do not purchase from?

yeah, the calculated field won’t work because you will return more than one row. You’ll have to bring in the subquery to the top level.

I think that you might need to vary your approach here. I think You need to start with a list of customers in your top level. Then have a subquery that has the InvcDtl, part table, and reference category maintenance. Include all of the reference category table (an outside join) In the sub, do a group by on customer number, and reference category. Then do a count of the invoice dtl lines in a calculated field.

That will give you a count of lines within each category for customer that bought things, and 0’s for the reference categories that they didn’t buy. If you don’t care about customers with no details, you can filter there (using the subquery filter) and make that your top level. If you want to include all of your customers then tie that to a top level with the customer list from the top table.

If you want to get the subquery into one row, only group by customer number and add a case statement for each calculated field so it only counts from one reference category. Then you will have a column for each reference category and you can filter easily from there.

Try this BAQ. I don’t have any reference categories in my system, but I think this should give you a count. Then you can filter out by 0 or not 0.

NotBuy.baq (135.8 KB)

1 Like

That BAQ is very close to what I am looking for. If I could just get all the Ref Cat to populate that would be perfect. In my system, it shows what they have purchased and only a few are zero’s. But otherwise, case statements is my choice of poison. Getting fairly decent at those. Much appreciated.

What’s missing?

I have 13 reference categories. So every customer should have 13 items in them, with zero’s for the ones they don’t buy, right?