Forum Discussion
Query with CTE gives error
your issue and thoughts about it are exactly what I'm facing today. Would be nice if it jsut passed through the query and used the results like it does in the preview. My query also works fine in PowerPivot with a recursive CTE and I was just trying it in Power BI but the same code in Power BI isn't accepted. cheers
I have the same issue with CTE. It will be much convenient to support CTE. I use a workaround to save data into excel and import it.
- Nobby9 years agoFrequent Visitor
It's a shame. I also have this problem. I've removed the CTE but the code is much less readable/maintainable. Ho hum.
- Mandr0id9 years agoAdvocate I
Same issue with CTE... Someone got it working?
- jimjao8 years agoNew Member
Hi all,
Using Power BI Desktop (October 2017), I was able to use CTE query with an OLE DB connection to the SQL Server.
So, Power BI does support CTE.
Jim Jao
- geoffwill9 years agoRegular Visitor
Having the same issue with CTEs, however was able to re-write to use a subquery and it works
- jimjao8 years agoNew Member
Hi all,
Using Power BI Desktop (October 2017), I was able to use CTE query along with an OLE DB connection to the SQL Server.
This is no longer truth.
Jim Jao
- Anonymous8 years agoNot applicable
Did you use Import or Direct Query?
Thanks
B
- roselilly237 years agoAdvocate V
I was getting the issue when using Direct Query with custom sql containing CTEs. I just re-wrote the query to have sub queries rather than the CTEs and it works fine now.
- MasterCMU6 years agoNew Member
Yes, this is still correct in Power BI Desktop November 2019 - confirmed it works ONLY through a OLE DB connection to SQL rather than through the SQL connection in Power BI. I came across the issue with CTE at the final "Apply" stage of Power Query with a Direct Connection and while the preview was working, the Apply and Close would fail with the same message as OP's. Using JimJao's fix with Ole DB I got it to Apply and Update. So it seems to be a bug in the SQL connector.
- Anonymous3 years agoNot applicable
I can confirm this works with OLE DB in PowerBI Desktop, but unfortunately scheduling an online refresh still seems to be causing problems, so the only way it works is republishing from locally updated results every time, which is still a very inconvenient workaround!