<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Aggregation Error Message in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Aggregation-Error-Message/m-p/4879999#M63848</link>
    <description>&lt;P&gt;Error Aggregation Handler (EAH) - 7F2F&lt;/P&gt;</description>
    <pubDate>Wed, 19 Nov 2025 15:25:14 GMT</pubDate>
    <dc:creator>marcinkozak1995</dc:creator>
    <dc:date>2025-11-19T15:25:14Z</dc:date>
    <item>
      <title>Aggregation Error Message</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Aggregation-Error-Message/m-p/3998680#M53478</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;I need to pull the company id related to the last billable stop in a series of stops(deliveries) where the following conditions are met:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;OL&gt;&lt;LI&gt;The order number is the same in both the stops table and order header table.&lt;/LI&gt;&lt;LI&gt;The stops must have billable codes LUL, LLD, DRL, and HPL in the stops event column (s.stp_event).&lt;/LI&gt;&lt;LI&gt;Since I want the company id related last billable stop I want the MAX stop sequence (s.stp_sequence) number which identifies each stop (1, 2, 3, etc.).&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I am having trouble getting the aggregation to work in the statement below. Am I missing something with this logic. Your help is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(SELECT cmp_id from stops s (nolock) where s.ord_hdrnumber = o.ord_hdrnumber and s.stp_event in ('LUL','LLD','DRL', 'HPL') and s.stp_sequence = MAX(s.stp_sequence)) as ReceiverID&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Error Message:&lt;/STRONG&gt; An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 18 Jun 2024 17:06:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Aggregation-Error-Message/m-p/3998680#M53478</guid>
      <dc:creator>cheid_4838</dc:creator>
      <dc:date>2024-06-18T17:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation Error Message</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Aggregation-Error-Message/m-p/3999056#M53485</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/677608"&gt;@cheid_4838&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It looks like you're running into an issue with using an aggregate function ('MAX()') directly in the 'WHERE' clause, which is not permitted in SQL.&amp;nbsp;&lt;/SPAN&gt;Please update your SQL statement as below and check if it can work or not...&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SELECT s.cmp_id AS ReceiverID
FROM stops s (nolock)
JOIN (
    SELECT ord_hdrnumber, MAX(stp_sequence) AS max_sequence
    FROM stops
    WHERE stp_event IN ('LUL', 'LLD', 'DRL', 'HPL')
    GROUP BY ord_hdrnumber
) max_stops
ON s.ord_hdrnumber = max_stops.ord_hdrnumber
   AND s.stp_sequence = max_stops.max_sequence&lt;/LI-CODE&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 01:26:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Aggregation-Error-Message/m-p/3999056#M53485</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-19T01:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation Error Message</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Aggregation-Error-Message/m-p/4879999#M63848</link>
      <description>&lt;P&gt;Error Aggregation Handler (EAH) - 7F2F&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2025 15:25:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Aggregation-Error-Message/m-p/4879999#M63848</guid>
      <dc:creator>marcinkozak1995</dc:creator>
      <dc:date>2025-11-19T15:25:14Z</dc:date>
    </item>
  </channel>
</rss>

