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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
StuartPQY
Frequent Visitor

SQL Script wont run in Power Query

Hello

 

I have some SQL that runs fine in MS SQL Studio, but will not run in Power Apps (in Excel ver 2402 build 16.0.17328.20550) 64 bit)

 

The error I get is 

DataSource.Error: Microsoft SQL: The identifier that starts with '
SELECT
CASE
WHEN AccountingDate < rca.InternalCommissionCalendarDate AND pbrc.RiskCarrierCode = 'xxx'
THEN 'C' is too long. Maximum length is 128.
Details:
DataSourceKind=SQL
DataSourcePath=insightmarts.xxxxx.com;xxxMart
Message=The identifier that starts with '
SELECT
CASE
WHEN AccountingDate < rca.InternalCommissionCalendarDate AND pbrc.RiskCarrierCode = 'HIC'
THEN 'C' is too long. Maximum length is 128.
ErrorCode=-2146232060
Number=103
Class=15
State=4

 

or 

StuartPQY_0-1731691778264.png

 

These are my PQ steps;

StuartPQY_1-1731691947509.png

 

 

Any thoughts without me sharing the SQL statement?

 

Thanks

 

Stuart

1 ACCEPTED SOLUTION
Anonymous
Not applicable

The fact that the error is coming from the SQL Server means that your steps are correct and the query is getting to the server so the problem is your SQL. 

 

--Nate

View solution in original post

3 REPLIES 3
PwerQueryKees
Super User
Super User

Please share your actual (failing) M code with the SQL statement in it. It is probably to do with quoted text inside quoted text.

StrategicSavvy
Resolver II
Resolver II

hi @StuartPQY 

I cannot see FROM clause in your SQL statement but maybe you truncated it in post. If not you can check if your SQL completed.

If everything is ok with SQL code I would advise trying query folding. To test it go for this steps:

1. Add your sql server connection string and select table that you would like to transform,

2. Create conditional colum where you add your logic to align with Case statement you want to get

3. Remove all other columns.

 

 

Anonymous
Not applicable

The fact that the error is coming from the SQL Server means that your steps are correct and the query is getting to the server so the problem is your SQL. 

 

--Nate

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.