Forum Discussion
Query with CTE gives error
It's a shame. I also have this problem. I've removed the CTE but the code is much less readable/maintainable. Ho hum.
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
- 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!