Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
mheggie
Frequent Visitor

Fabric Warehouse Incorrect Query Results

I'm hoping to get some guidance from the group on where to go with this.  I have 2 queries that run in sequence that read from my Fabric data warehouse.  The queries are different and should yield different results but when they run, they actually return the same data.  

 

Query #1:
DECLARE @StartingDate DATE = DATEADD(YEAR, -10, DATETRUNC(year, GETDATE()));

select * from rpt.vw_DimGLAccount
where [GL Account Key] in (SELECT F.ExpenseGLAccountKey
                    FROM gold.FactPayrollHistory F
                         JOIN gold.DimDate D ON F.PeriodEndDateKey = D.DateKey
                    WHERE D.CalendarDate >= @StartingDate);
 
Returns 2365 rows as it should

Query #2:
DECLARE @StartingDate DATE = DATEADD(YEAR, -10, DATETRUNC(year, GETDATE()));

select * from rpt.vw_DimGLAccount
where [GL Account Key] in (SELECT F.LiabilityGLAccountKey
                    FROM gold.FactPayrollHistory F
                         JOIN gold.DimDate D ON F.PeriodEndDateKey = D.DateKey
                    WHERE D.CalendarDate >= @StartingDate);
 
Should return 67 rows but returns the same 2365 rows as the first query.
 
If I run these in reverse order, when the second query returns the same results as the first one run.
 
It looks like the DW optimizer thinks these 2 queries are the same.  It doesn't recognize that the the queries have different column names in the subquery.
 
I have found a way to work around this specific instance by restructuring one of the queries so it is distinctly different from the other.  However, I can't guarantee that similar queries like above won't happen.  This feels like a bug to me.
 
Have you seen this?  Does anyone have any guidance on how things like this can be reported to Microsoft?  
 
Any thoughts / guidance you can provide is greatly appreciated!
1 ACCEPTED SOLUTION

yeah, best to raise a ticket with product support - use the menu above Support > Product Support to log the new support casePlease make it clear in the ticket that removing the variable StartingDate resolves it; and the issue seems to be happening quite recently. 

 

If my workaround helped please mark it as a solution, so that others in this situation can take advantage of this workaround! 

 

I trust this will be helpful. If you found this guidance useful, you are welcome to acknowledge with a Kudos or by marking it as a Solution.

View solution in original post

6 REPLIES 6
deborshi_nag
Resident Rockstar
Resident Rockstar

Hello @mheggie 

 

It is a very strange behavious indeed! Can you try using a WITH clause instead of a IN clause and let me know if you see any difference in the behaviour? Here's one of your query with a WITH clause. 

 

-- Derive the starting date: first day of the current year minus 10 years
DECLARE @StartingDate DATE = DATEADD(YEAR, -10, DATETRUNC(year, GETDATE()));

WITH PayrollGL AS (
    SELECT DISTINCT F.ExpenseGLAccountKey
    FROM gold.FactPayrollHistory AS F
    JOIN gold.DimDate AS D
      ON F.PeriodEndDateKey = D.DateKey
    WHERE D.CalendarDate >= @StartingDate
)
SELECT a.*
FROM rpt.vw_DimGLAccount AS a
JOIN PayrollGL AS p
  ON a.[GL Account Key] = p.ExpenseGLAccountKey;
 

 

I trust this will be helpful. If you found this guidance useful, you are welcome to acknowledge with a Kudos or by marking it as a Solution.

Thanks for your suggestion. 

 

I tested with your query for both expense and liability and they both return what is expected.  I had already worked around this by replacing @StartingDate in the where clause with the expression I was using to calculate it and it works.

 

select * from rpt.vw_DimGLAccount
where [GL Account Key] in (SELECT F.ExpenseGLAccountKey
                    FROM gold.FactPayrollHistory F
                         JOIN gold.DimDate D ON F.PeriodEndDateKey = D.DateKey
                    WHERE D.CalendarDate >= DATEADD(YEAR, -10, DATETRUNC(year, GETDATE())));
 
There are definitely some workarounds for this which is why it feels like a bug to me. 
 
The process that uses this has been running  successfully in production since May 2025.  This issue just appeared in the last few weeks.

yeah, best to raise a ticket with product support - use the menu above Support > Product Support to log the new support casePlease make it clear in the ticket that removing the variable StartingDate resolves it; and the issue seems to be happening quite recently. 

 

If my workaround helped please mark it as a solution, so that others in this situation can take advantage of this workaround! 

 

I trust this will be helpful. If you found this guidance useful, you are welcome to acknowledge with a Kudos or by marking it as a Solution.
stoic-harsh
Resolver III
Resolver III

Hi @mheggie,

Before concluding it an engine bug or caching issue, I would like to first think purely from a data/query perspective. If you are only looking at row counts as validation, it is possible that even if there are only 67 distinct liability keys,  [GL Account Key] in rpt.vw_DimGLAccount may contain 2,365 rows matching these 67 keys (given, no DISTINCT is being applied in the outer query).

Another reason could be that [LiabilityGLAccountKey] and [ExpenseGLAccountKey] contain identical values, or one is a subset of other, over the filtered date range.

Could you first verify this, by looking at the actual result sets, rather than relying solely on row counts?

Thanks for the feedback.  I have evaluated the results along with the counts.  What I've shared in my post is accurate.  I should get 2365 rows returned for one query and 67 for the other.  LiabilityGLAccountKey and ExpenseGLAccountKey values are not identical and are not a subset of one another.  Liabilities post to a different place in the GL than expenses.

 

If I change the "select *" in each query to a "select count(*)", the numbers returned are correct.  When I then change the "count(*)" back to "*", it returns the same result for both.

 

Also ... the process with this logic has been running successfully in production since May 2025.  It is only in the last few weeks that this has been a problem.  I've tested this with other keys that reference the same dimension and can consistently re-create the issue.

 

When the second query runs, it notes that it is using cached results.

v-echaithra
Community Support
Community Support

Hi @mheggie ,

Thank you for reaching out to Microsoft Community.

I recommend reporting the bug using the link below on the MS Fabric Forum.

Issues - Microsoft Fabric Community

Thanks & Regards,

Helpful resources

Announcements
FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Fabric Update Carousel

Fabric Monthly Update - March 2026

Check out the March 2026 Fabric update to learn about new features.