Solved

BAQ - Customers with no invoices for the past 2+ years

  • 8 April 2021
  • 6 replies
  • 249 views

Hello all,

I’m creating a dashboard with a few tabs.  I thought this particular one was fairly simple, but it’s not returning correctly.  All I need are all customers with no invoices for the past two years.  I’m clearly not entering the criteria correctly so if someone could point me in the right direction, I’d appreciate it!  I’ll post my criteria below.  I will post the questions I have on the other 2 BAQ’s separately.

 

Thank you!

Erin

icon

Best answer by fred 8 April 2021, 22:10

View original

6 replies

Userlevel 3

Couple ways to do this:

  1. Make sure you’re doing a Right Outer Join (get all the rows from Customer regardless if they have invoices).  Set the SubQuery Criteria so that you are getting where InvcHead is null.  Set the SubQuery Options so that it’s a distinct and your Display is only going to be customer information.
  2. Move InvcHead to a subquery, set the subquery options to distinct returning only custid.  For your TopLevel Query have Customer and left join (all rows from Customer) to the subquery of InvcHead.  Set the SubQuery Criteria where InvcHead is null.

Either route should get you there.

Fred,

Thanks so much for your quick response!  I’m modifying my query to match your first option, and I have done everything except “ Set the SubQuery Criteria so that you are getting where InvcHead is null.”  

How do I do that?  Would I not already get that by making it a right join?

Hello Erin,

 

What you need to do is create a subquery with just the InvcHead table, where you query the count of invoice numbers (with your date criteria set on the table), grouped by CustNum. Then you bring that subquery to the top level and join it to the Customer table on the CustNum field. Set the join so that you retrieve all rows from the Customer table, and when you run the query, the customers with no invoices will have a NULL for the number of invoices field (see image). Then you can create a calculated field in the top level return 0 if the field is null, and the original value otherwise.

Let me know if you have any questions.

Thanks,

Matthew Morgan

DESHAZO Crane Company

Userlevel 3

The Subquery criteria is on the bottom of the canvas where you define table criteria and relations.  It’s another tab.

You want to add a criteria where the subquery’s value is null so that you ONLY get customers who don’t have rows in the subquery.  When they don’t have rows, the subquery’s values will be null.  Easy way to get the “where they don’t have orders” that you are wanting.

Matthew,

Thank you for your response.  I’m a newb and need things broken down at times.  ;)

I have created my query but the customers with no invoices are displaying with zeroes already.  They are not null.  I am posting my BAQ in case you see something I’ve done wrong.  If this is correct (and I’ve tested quite a few to check invoice dates to make sure they match with what I need) then I can filter out the non-zeroes in the db and I’m good.  I do have one question however.  I pulled up Customer Tracker and ran a search to see how many customers we had, and we have 3,960.  So shouldn’t there also be 3,960 results in my query?  How do I end up with 4,094?

Results 

 

Thanks to both of you, I think I finally have it!  

Now to move on to my next queries - the trickier ones.  I’m not very good yet with subqueries, so this should be an awesome learning experience!

Reply