<?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: Odd DISTINCT behavior from lakehouse SQL Analytics Endpoint in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3571762#M182</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/641130"&gt;@gmangiante&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for using Microsoft Fabric Community.&lt;/P&gt;
&lt;P&gt;Apologies for the issue that you are facing.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This might require a deeper investigation from our engineering team about your workspace and the logic behind it to properly understand what might be happening.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please go ahead and raise a support ticket to reach our support team:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://support.fabric.microsoft.com/support" target="_blank" rel="noopener nofollow noreferrer"&gt;https://support.fabric.microsoft.com/support&lt;/A&gt;&lt;BR /&gt;Please provide the ticket number here as we can keep an eye on it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Dec 2023 05:36:34 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-12-07T05:36:34Z</dc:date>
    <item>
      <title>Odd DISTINCT behavior from lakehouse SQL Analytics Endpoint</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3569132#M181</link>
      <description>&lt;P&gt;Hello - this is a bit of an involved issue (apologies for length!) that started in PowerBI but seems to be really a SQL Analytics Endpoint oddity. I was creating a very simple bar chart report with a very simple DirectQuery data model - 3 tables coming from our lakehouse SQL Analytics Endpoint - and found that, for the Y-axis, if I asked for a COUNT, it worked fine; but if I asked for a COUNT DISTINCT, I got a very nondescript "SQL command could not be executed" error - but only for certain selections in my "Keyword" slicer. I grabbed the diagnostic output, found the query that PowerBI had constructed, and popped it into a live SQL query against the endpoint, and got exactly the same result - "Msg 100000 SQL command could not be executed." I've put the query below, whittled down so it only has relevant fields, and noted a couple of things I found that got around this mystery error, but none of them help me with my COUNT DISTINCT reporting requirement. Hoping someone has some insight!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; SELECT
    basetable0.c55,
    (COUNT_BIG(DISTINCT a0) + MAX(CASE WHEN a0 IS NULL THEN 1 ELSE 0 END)) AS a0
FROM 
(
    (
        SELECT
            t4.PerformanceNo AS c43,
            t4.Facility AS c55,
            t3.SeatNo AS a0
        FROM 
        (
            (
                select
                    MyTable.PerformanceNo as PerformanceNo,
                    MyTable.SeatNo as SeatNo
                from
                    dbo.us_performance_seats as MyTable
            ) AS t3
            INNER JOIN 
            (
                select
                    MyTable.PerformanceNo as PerformanceNo,
                    MyTable.Facility as Facility
                from
                    dbo.us_performances as MyTable
            ) AS t4
            on t3.PerformanceNo = t4.PerformanceNo
        )
    ) AS basetable0
    INNER JOIN 
    (
        SELECT
            t4.PerformanceNo AS c43,
            t4.Facility AS c55
        FROM 
        (
            (
                select
                    MyTable.PerformanceNo as PerformanceNo,
                    MyTable.Keyword as Keyword
                from
                    dbo.us_performance_keywords as MyTable
            ) AS t0
            INNER JOIN 
            (   
                select
                    MyTable.PerformanceNo as PerformanceNo,
                    MyTable.Facility as Facility
                from
                    dbo.us_performances as MyTable
            ) AS t4
            on t0.PerformanceNo = t4.PerformanceNo
        )
        WHERE t0.Keyword = 'Keyword1'
        GROUP BY t4.PerformanceNo,t4.Facility
    ) AS semijoin1
    on 
    (semijoin1.c43 = basetable0.c43 OR semijoin1.c43 IS NULL AND basetable0.c43 IS NULL)
    AND 
    (semijoin1.c55 = basetable0.c55 OR semijoin1.c55 IS NULL AND basetable0.c55 IS NULL)
)

GROUP BY basetable0.c55&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Things that made the error go away:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;removing the DISTINCT from the outer SELECT (same behavior as in PowerBI)&lt;/LI&gt;&lt;LI&gt;changing the "Keyword1" filter to "Keyword2" (same behavior as in PowerBI) - I checked out the raw results prior to the GROUP BY, and Keyword1 doesn't have a huge number of rows more than Keyword2 - like 26K instead of 13K - so it doesn't feel like a data volume issue to me&lt;/LI&gt;&lt;LI&gt;taking out the MAX(CASE) statement for [a0] in the outer SELECT - instantly returned expected results&lt;/LI&gt;&lt;LI&gt;adding a TOP N clause to the SELECT for [basetable0] - tried numbers as big as 10M, didn't matter how large or small - as long as there was a TOP N, it was happy and returned the expected results immediately (adding TOP N to the SELECT for [semijoin1] had no effect)&lt;/LI&gt;&lt;LI&gt;removing the very bottom null-join-check (OR semijoin1.c55 IS NULL and basetable0.c55 IS NULL) also produced instant correct results - no other parts of the join had any effect when removed - and note that c55, the Facility column, does not contain any nulls&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 05 Dec 2023 18:58:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3569132#M181</guid>
      <dc:creator>gmangiante</dc:creator>
      <dc:date>2023-12-05T18:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Odd DISTINCT behavior from lakehouse SQL Analytics Endpoint</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3571762#M182</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/641130"&gt;@gmangiante&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for using Microsoft Fabric Community.&lt;/P&gt;
&lt;P&gt;Apologies for the issue that you are facing.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This might require a deeper investigation from our engineering team about your workspace and the logic behind it to properly understand what might be happening.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please go ahead and raise a support ticket to reach our support team:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://support.fabric.microsoft.com/support" target="_blank" rel="noopener nofollow noreferrer"&gt;https://support.fabric.microsoft.com/support&lt;/A&gt;&lt;BR /&gt;Please provide the ticket number here as we can keep an eye on it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 05:36:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3571762#M182</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-12-07T05:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Odd DISTINCT behavior from lakehouse SQL Analytics Endpoint</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3575009#M183</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/641130"&gt;@gmangiante&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;We haven’t heard from you on the last response and was just checking back to see if you got a chance to create a support ticket. If yes please share the details here.&lt;BR /&gt;Otherwise, will respond back with the more details and we will try to help. &lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 18:43:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3575009#M183</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-12-08T18:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Odd DISTINCT behavior from lakehouse SQL Analytics Endpoint</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3575048#M184</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/641130"&gt;@gmangiante&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the adding the ask in so much details , this aloways helps .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am sorry as i do not have a solution but when PowerBi is converting the SQL into DAX query I am sure , somthing is happening there . I suggest you to please see if you can simplify the query and even better if you add that in a view and call the view from PowerBI ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really want to help but without the data and the schema i cannot do much from myside for now .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;BR /&gt;Himanshu&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 19:29:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Odd-DISTINCT-behavior-from-lakehouse-SQL-Analytics-Endpoint/m-p/3575048#M184</guid>
      <dc:creator>HimanshuS-msft</dc:creator>
      <dc:date>2023-12-08T19:29:49Z</dc:date>
    </item>
  </channel>
</rss>

