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
f_e_user
Regular Visitor

CTE Query Gives Error

Hello,

I've a model data made with Import Connectivity.
I've been tasked to convert it to DirectQuery and in several table they are all done with CTE.
I have a CTE SQL Query

 

 

 

 That 

  • Runs fine on SQL Server when I launch this query
  • I can see the data in PowerQuery

When I click "Close and Apply" in PowerQuery I do receive this error

f_e_user_0-1676652483028.png

 

  1. Can you help me to solve this issue?
  2. Does Direct Query Supports CTE like WITH ?

 

5 REPLIES 5
AnushaSri
Resolver II
Resolver II

Hi f_e_user,

 

You need to start With CTE query with a  Semicolon ";"

So it should be like ; With CTE 

Just add a semicolon before your CTE expression will solve

grantsamborn
Solution Sage
Solution Sage
smpa01
Community Champion
Community Champion

Hope this helps

https://stackoverflow.com/a/64217559/11156131

 

You can call each of the query tables seprately, create dat amodel, create measures and have it report exactly like the SQL above

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
goncalogeraldes
Super User
Super User

Hi @f_e_user, I think that you are only missing a ";". Try the following:

WITH NewestOS AS (
SELECT GS_OS_Data.ResourceID
	, TimeStamp
	, Caption0
FROM v_GS_Operating_System as GS_OS_Data
INNER JOIN (SELECT ResourceID
	, MAX(TimeStamp) as MaxDate
	FROM v_GS_Operating_System
	GROUP BY ResourceID
) MaxFilter on  GS_OS_Data.ResourceID = MaxFilter.ResourceID and MaxFilter.MaxDate = GS_OS_Data.TimeStamp
);
SELECT v_R_System.ResourceID 
  , v_R_System.Name0    
    , v_R_System.Name0 + '.' + v_R_System.Full_Domain_Name0 as Resource_Names0
    , v_R_System.Resource_Domain_OR_Workgr0 AS 'DOMAIN'
    , CASE v_R_System.Client0
            WHEN 1 THEN 'INSTALLED'
            ELSE 'MISSING'
        END AS ClientStatus
    , v_R_System.Client_Version0
    , v_R_System.Last_Logon_Timestamp0
    , CASE NewestOS.Caption0
        WHEN NULL THEN v_R_System.Operating_System_Name_and0
        ELSE NewestOS.Caption0
    END AS OSNAME
    , V_GS_System.SystemRole0
FROM v_R_System
LEFT OUTER JOIN NewestOS on v_R_System.ResourceID = NewestOS.ResourceID
LEFT OUTER JOIN v_GS_System ON v_R_System.ResourceID = v_GS_System.ResourceID
WHERE v_R_System.Operating_System_Name_and0 LIKE '%Microsoft%'

 

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!

You can also check out my LinkedIn!

Best regards,
Gonçalo Geraldes

f_e_user_0-1676653493533.png

It didn't solve the issue.

Helpful resources

Announcements
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.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

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