BAQ Filter Enquiry

,

Hi Everyone,

I’m trying to create a BAQ to display the total number of POs along with the total amount by vendor.

In addition to that, I would also like to create a filter to allow sorting by POHeader.OrderDate, any idea on how to achieve this?
Adding orderdate to the BAQ would return 0 result which is expected as i was grouping by vendor.

select
[Vendor].[Name] as [Vendor_Name],
(count(POHeader.PONum)) as [Calculated_NoOfPOs],
(sum(POHeader.DocTotalOrder)) as [Calculated_TotalSGD]
from Erp.POHeader as POHeader
inner join Erp.Vendor as Vendor on
POHeader.Company = Vendor.Company
and POHeader.VendorNum = Vendor.VendorNum
group by [Vendor].[Name]

Thanks!

Pretty much just how you have it set up now.

Add a MAX() field to sort by the last order date.

select 
	[Vendor].[Name] as [Vendor_Name],
	(SUM(POHeader.DocTotalOrder)) as [Calculated_SumOrders],
	(COUNT(POHeader.PONum)) as [Calculated_CountOrders],
	(MAX(POHeader.OrderDate)) as [Calculated_LastOrderDate]
from Erp.POHeader as POHeader
inner join Erp.Vendor as Vendor on 
	POHeader.Company = Vendor.Company
	and POHeader.VendorNum = Vendor.VendorNum
group by [Vendor].[Name]

I’m planning to use this BAQ on a dashboard, and subsequently create a data range filter to display the total amount of PO and total amount of the vendor based on the selected date range :slight_smile:

In order to do that, I would need to add the orderdate to the display column in BAQ, but doing so would ruin my BAQ as it would not return any result if I do that. However if I don’t pull it out, I can’t filter the orderdate in dashboard

select 
	[Vendor].[Name] as [Vendor_Name],
	[POHeader].[PONum] as [POHeader_PONum],
	[POHeader].[OrderDate] as [POHeader_OrderDate],
	[POHeader].[DocTotalOrder] as [POHeader_DocTotalOrder],
	[SubQuery2].[Calculated_TotalSumPOForVendor] as [Calculated_TotalSumPOForVendor],
	[SubQuery2].[Calculated_TotalCountPOForVendor] as [Calculated_TotalCountPOForVendor]
from Erp.POHeader as POHeader
inner join Erp.Vendor as Vendor on 
	POHeader.Company = Vendor.Company
	and POHeader.VendorNum = Vendor.VendorNum
inner join  (select 
	[Vendor1].[VendorNum] as [Vendor1_VendorNum],
	(sum(POHeader1.DocTotalOrder)) as [Calculated_TotalSumPOForVendor],
	(count(POHeader1.PONum)) as [Calculated_TotalCountPOForVendor]
from Erp.POHeader as POHeader1
inner join Erp.Vendor as Vendor1 on 
	POHeader1.Company = Vendor1.Company
	and POHeader1.VendorNum = Vendor1.VendorNum
group by [Vendor1].[VendorNum])  as SubQuery2 on 
	Vendor.VendorNum = SubQuery2.Vendor1_VendorNum

Subquery 1:

Vendor_Name	Name
POHeader_PONum
POHeader_OrderDate
POHeader_DocTotalOrder

From Subquery2 --> Calculated_TotalSumPOForVendor
From Subquery2 --> Calculated_TotalCountPOForVendor

Linked On Subquery1 Vendor_VendorNum → Subquery2 Vendor1_VendorNum →

Subquery 2:

Vendor1_VendorNum         [GROUP BY CHECKED]
Calculated_TotalSumPOForVendor
Calculated_TotalCountPOForVendor

You could turn on sums in the dashboard and use the dashboard grouping as as an alternative
to the summing subquery.

Thank you very much Kevin!
Appreciate it very much.

I was trying to allow sorting by order date but leaving the details out tho.
For example, the BAQ would just display these 3 field in a single row.

Vendor: ABC
TotalPOCount: 100
TotalPOAmount: 999

I also want to be able to add a orderdate filter to narrow the date based on my date range selection.

For example, filter selection would be:

Date > 1-1-23 to Date 30-1-23
Vendor: ABC

Displayed result, in a single row by vendor:

Vendor: ABC
TotalPOCount: 12
TotalPOAmount: 124

Is it possible to achieve this?
Understand that there are sums in dashboard to summarize the amount but it wouldn’t look as nice as the default look.

Yes, you could use a parameter, and filter in the criteria.
You wouldn’t SEE the dates, but it would return the correct data.

Your first query is fine for that.

Actions → Define Parameters

You’re a lifesaver!!! That’s exactly what I’m looking for.

Thank you for the patience and awesome help provided Kevin!

1 Like

You’re most welcome.

This site has been a godsend. I try to give back a small amount of what I take out of it.

1 Like