web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Query but Method = Max can't be applied to Date values

(1) ShareShare
ReportReport
Posted on by 841
So I'm building a customer query. Including their contact details, along with some sales summary fields, such as total quantity and total amount. I would like to also present the user with their last sale date. But applying the Max method to a Date field isn't allowed? If AL is supposed to emulate basic T-SQL then the MAX method is certainly available using that route. Here's my code below. Any suggestions as to how I can add the most recent Sales Line Posting Date to this result set?
 
/// <summary>
/// Query DCH Customer Sales Totals (ID 50003).
/// </summary>
query 50003 /DCH Customer Sales Totals/
{
Caption = 'DCH Customer Sales Totals';
QueryType = Normal;
//OrderBy = Descending(Posting_Date);
 
elements
{
dataitem(Customer; Customer)
{
column(No; /No./)
{
}
column(Name; Name)
{
}
column(Address; Address)
{
}
column(Address2; /Address 2/)
{
}
column(City; City)
{
}
column(County; County)
{
}
column(PostCode; /Post Code/)
{
}
column(PhoneNo; /Phone No./)
{
}
column(MobilePhoneNo; /Mobile Phone No./)
{
}
column(EMail; /E-Mail/)
{
}
column(SalespersonCode; /Salesperson Code/)
{
}
column(MailOK; /Mail OK/)
{
}
column(EmailOK; /Email OK/)
{
}
column(Location_Code; /Location Code/)
{
 
}
dataitem(Sales_Line; /Sales Line/)
{
DataItemLink = /Sell-To Customer No./ = Customer./No./;
SqlJoinType = InnerJoin;
 
column(Quantity; Quantity)
{
Caption = 'Sum Quantity';
Method = Sum;
}
column(Amount; Amount)
{
Caption = 'Sum Amount';
Method = Sum;
}
// Need to present the user with the last sale date. Method = Max doesn't work for Date data types. :(
/*column(Posting_Date; /Posting Date/)
{
Caption = 'Last Sale';
}*/
}
}
}
 
trigger OnBeforeOpen()
begin
 
end;
}
  • Greg Kujawa Profile Picture
    841 on at
    I tried adding this as a ColumnFilter but that wasn't the ticket.
     
    ColumnFilter = Posting_Date = filter(=max("Posting Date"));
  • Suggested answer
    YUN ZHU Profile Picture
    103,712 Super User 2026 Season 2 on at
    Hi, I think you could think of it differently, for example,
     
    Hope this helps.
    Thanks.
    ZHU
  • Greg Kujawa Profile Picture
    841 on at
    Thanks for your reply! I was looking at utilizing similar logic, but a couple of other columns in the Sales Line I want to look at to include sum totals. Such as Quantity and Amount. I'll try to use what you suggested and see how it goes!
  • Suggested answer
    Greg Kujawa Profile Picture
    841 on at
    UPDATE: I employed something that is based on your very helpful article about using a query to populate a temporary table, and then use that as a basis for a page.


    Using this logic I was able to determine the Last Sale Date value through a local procedure on the new page. And include that value in the result set. All good now!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 743 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 546 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 332 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans