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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.