cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
michaeljc70 Regular Visitor
Regular Visitor

Query with CTE gives error

I used SQL Server and a query that uses a CTE.  It gives me an error "Incorrent syntax near the Keyword 'WITH'. ......."if this is a common table expression......previous statement must be terminated witha  semicolon."

 

The query runs fine outside of Power BI.  I tried putting a semi-colon before the 'WITH', but that didn't work.   I see the data in the grid, but can't apply query changes and get the error 

22 REPLIES 22
michaeljc70 Regular Visitor
Regular Visitor

Re: Query with CTE gives error

One more thing...though I can see my data under "Edit Queries", I cannot create a visualization because the query doesn't appear under "Fields". 

austinsense Established Member
Established Member

Re: Query with CTE gives error

Are you accessing a view that uses a CTE or did you write a SQL query that uses a CTE?

 

If it's the latter, then I'd suggest creating a view and then querying the view.

 

Austin is VP Operations at PowerPivotPro and a professional self-service enthusiast 🙂
michaeljc70 Regular Visitor
Regular Visitor

Re: Query with CTE gives error

I wrote a query that uses a CTE. I don't have permissions to create a view or stored procedure. 

austinsense Established Member
Established Member

Re: Query with CTE gives error

Gotcha, putting a custom sql query into the query builder is not recommended - as you can see Smiley Happy

 

Here are your options ...

1. Create a view - sounds like this isn't an option for you

2. Re-write the query without using a CTE - that would be a good test of your SQL skills

3. Stop using the custom sql code, query the underlying tables using the GUI, and use PQ to create the output you want - that would be a good test of your PQ skills

Austin is VP Operations at PowerPivotPro and a professional self-service enthusiast 🙂
Highlighted
michaeljc70 Regular Visitor
Regular Visitor

Re: Query with CTE gives error

I am not sure why it isn't recommended. I don't see the documentation saying that and I don't see a list of query limitiations.   

 

I am evaluating Power BI to determine in my organization wants to buy and use it as a visualization tool.  I am not trying to "test my skills".   I am trying to evaluate products to see how they work (or if they work in this case).  

 

I cannot import the tables and join them because they are too large. I cannot use Direct Query because it doesn't support many to many relationships.  All I see are a lot of llmitations.

 

Power BI is supposed to be self-service.  That typically means not writing views or stored procedures (and generally not CTEs) and if a feature is there, I expect it to work.  

austinsense Established Member
Established Member

Re: Query with CTE gives error

FYI, most people start these conversations with "thanks for trying to help me ..."

 

Writing custom SQL query generally works just fine - it's just recommended that you don't do it that way, that you create a view. Along those lines self-service BI doesn't mean that people are going to write SQL queries with CTEs to access the data, so I don't see not being able to do that in the tool as a major limitation to self-service BI.  The only limitation that you have here is that you need a view created in your database, and that's not a limitation of this product.

 

To get around the limitation of creating a view, this solution does allow you (as a self-service tool) to take the tables out of your database and do the joining yourself using the query editor GUI.  Your data must be very, very large if you can't get that to work in Power BI, and if your data is that large I'll ask you again, why aren't you doing that in a view in your database?  If you have a nail that you need to put in a wall and you reach in your bag and get a screwdriver, well I don't think that's the screwdriver's fault.

 

One last point, I realize you're not trying to "test your skills" but I will say that this product is not BI magic dust - it does require some skills to use. If you're the type of person that can write a SQL query with a CTE then you'll be able to figure it out.  Unless you don't want to figure it out.

Austin is VP Operations at PowerPivotPro and a professional self-service enthusiast 🙂
michaeljc70 Regular Visitor
Regular Visitor

Re: Query with CTE gives error

I  do appreciate any help.  I was just hoping for an answer as to why it doesn't work rather than how to work around it.  If there are limitations in queries in Power BI, that really should be documented by Microsoft.  

 

This would be  used with a data warehouse, so the tables often have millions of rows.  

 

As a developer, of course I can write queries (or views or stored procedures), but management doesn't really understand how this all works and thinks anyone can get a tool and drag tables and fields around and get reports and visualizations. They see a 2 hour demo and think it is so easy (which it is if you know the tool and have cultivated data).   At a minimum,  I believe unless your dataset is small and/or carefully cultivated,  IT (or technical business people) needs to create views, cubes or queries.  

 

I completely understand that that is not a Power BI limitation strictly, but a self-service limitation that all these tools have.   

 

I'm going to communicate this all to my client, and if they don't buy it suggest they have several potential report writers try and create reports with the data warehouse as is.  

austinsense Established Member
Established Member

Re: Query with CTE gives error

Ok, cool we're on the same page Smiley Happy

 

We build and work with models pretty regularly that have 10 million+ rows in them so I'm curious what issues you're having - is Power BI throwing out some kind of error when you try to bring in your data?  Someone from this community could definitely help you work through this issue.

Austin is VP Operations at PowerPivotPro and a professional self-service enthusiast 🙂
michaeljc70 Regular Visitor
Regular Visitor

Re: Query with CTE gives error

If you aren't writing a query, Power BI doesn't seem to support many to many relationships if you can get the data loaded.

 

Some of the tables have 100 million rows.   That is why I don't think it is realistic to not be writing quereis or at least views that break down the data further.  

 

As an example, we have around 500k accounts and then daily information about each account in a table.  Over 100 days, that is 50 million records.

Helpful resources

Announcements
New Kudos Given Badges Coming

New Kudos Given Badges Coming

We're rolling out new Kudos Given badges. Find out how many Kudos you've given.

Microsoft Implementation for Communities Wins Award

Microsoft Implementation for Communities Wins Award

Learn about the award-winning innovation that was implemented across Microsoft’s Business Applications Communities.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Kudoed Authors (Last 30 Days)
Users online (1,726)