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
Petter120
Helper I
Helper I

Parameter in MYSQL query is not working

Hi i have a MySQL query im trying to run from Power query editor and it usually work but this query has a parameter inside of it and its givning me an error:

SET @row_index := 1;

SET @row_index := -1;
SELECT DATUM,"FM" As Skift, Format(stddev(Duration),2) As STDEV, Format(avg(Duration),2) As Arimetric_Mean, (SELECT Format(AVG(subq.Duration),2) as median_value
FROM  (
    SELECT  s.DATUM, @row_index:=@row_index + 1 AS row_index, s.Duration
    FROM production_db.cykeltider_t as s
    WHERE s.LASTTID >= '2022-09-01 05:45:00' and s.LASTTID < '2022-09-01 15:00:00'  and s.OMRADE = "1022-08" 
    ORDER BY s.Duration) AS subq
  WHERE subq.row_index 
  IN (FLOOR(@row_index / 2) , CEIL(@row_index / 2))) as T

FROM production_db.cykeltider_t
WHERE LASTTID >= '2022-09-01 05:45:00' and LASTTID < '2022-09-01 15:00:00'  and OMRADE = "1022-08";

 

I am getting this error, an anyone assist me with this?

Petter120_0-1665616309143.png

DataSource.Error: ODBC: ERROR [42000] [MySQL][ODBC 8.0(w) Driver][mysqld-8.0.28]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT DATUM,"FM" As Skift, Duration, Duration
FROM production_db.cykeltider_t, ' at line 2
Information:
DataSourceKind=Odbc
DataSourcePath=dsn=MY_SQL
OdbcErrors=[Table]

 

Best regards 
Petter

3 REPLIES 3
ImkeF
Community Champion
Community Champion

Sorry, no further ideas from me here.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Community Champion
Community Champion

Hi @Petter120 ,
could this actually be an issue with the double quotes? They act as escape signs in Power Query.
Couldn't you replace them with single quotes in your SQL-statement?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

No that didnt work

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.