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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Noyer
Helper I
Helper I

How to Reference Parameter in ODBC Query

Hi All

 

I've got the following query and it works fine.  The lines below are from the advanced editor:

 

let
Source = Odbc.Query("dsn=DW", "SELECT * FROM mwrdw.dbo.as_sales WHERE fiscyear >= 2020 ")
in
Source

 

I'm trying to replace the fiscyear with a parameter value but I'm failing.  I've set up a new parameter ("Parameter1") with a current value of 2020.  I've then changed the text in the advanced editor to:

 

let
Source = Odbc.Query("dsn=DW", "SELECT * FROM mwrdw.dbo.as_sales WHERE fiscyear >= "Parameter1" ")
in
Source

 

I get a "Token Comma expected" error.  I've tried a couple of variations with no success.  The fiscyear field in the source contains four digit years stored as numbers.

 

I'm trying to set up a parameter that I can pass to the service allowing me to edit the fisc year there.  The table stores a huge amount of data (too much for the desktop application that gives a memory error when too many years are loaded) but Power BI service will handle this. 

 

If I can get the parameter to work I can then have a much smaller desktop filesize while I work but pass many more years to the file in the service..  I hope I've explained that right!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Noyer ,

Refer if this can help: https://www.biinsight.com/power-bi-desktop-query-parameters-part-1/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Noyer ,

Refer if this can help: https://www.biinsight.com/power-bi-desktop-query-parameters-part-1/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi

Thanks for the quick reply.  Using the link you suggested I amended the advanced editor to:

 

let
Source = Odbc.Query("dsn=DW", "SELECT * FROM mwrdw.dbo.as_sales WHERE fiscyear >= "&Parameter1&" ")
in
Source

 

However I now get the following error:

 

Expression.Error: We cannot apply operator & to types Text and Number.
Details:
Operator=&
Left=SELECT * FROM mwrdw.dbo.as_sales WHERE fiscyear >=
Right=2020

 

I don't know what that means..?

You are passing as text parameter, it needs number

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

That solved it!  When I put '2020in the parameter it worked - thanks!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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