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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Passing PowerBI Parameter To A Stored Procedure

CustomerKeyParameter.jpgGeographyKey.jpgHello everyone,

 

I am trying to create parameters within PowerBI so that I can pass the values to the parameters of a stored procedure.

This is the code for the procedure, which uses the AdventureWorksDW2019 database:

 

CREATE OR ALTER PROCEDURE [dbo].[TestProcWithParameters]
@CustomerKey INT
, @GeographyKey INT
AS
BEGIN

SELECT
[DC].[CustomerKey]
, [DC].[FirstName] + [DC].[LastName] AS [CustomerName]
, [DC].[GeographyKey]
, [DG].[EnglishCountryRegionName]
FROM [dbo].[DimCustomer] [DC]
INNER JOIN [dbo].[DimGeography] [DG]
ON [DC].[GeographyKey] = [DG].[GeographyKey]
WHERE
[DC].[CustomerKey] = @CustomerKey
AND [DC].[GeographyKey] = @GeographyKey;

END;

 

I'm attaching screenshots of the parameters to this post.

 

I followed the advice of this post, but I get an error:

https://community.powerbi.com/t5/Desktop/Execute-SQL-Server-stored-procedure-input-parameters-with-p...

 

let
Source = Sql.Database("localhost", "AdventureWorksDW2019", [Query="EXECUTE TestProcWithParameters " & CustomerKey & ", " & GeographyKey])
in
Source

Expression.Error: We cannot apply operator & to types Text and Number.
Details:
Operator=&
Left=EXECUTE TestProcWithParameters
Right=1

 

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

The error tells you exactly what the issue is.

 

If you want IDs as part of your query string, they need to be in text format. So you have two options

  1. Define the parameters as text-valued rather than numbers.
  2. Convert the number to text in your query.

 

"EXECUTE TestProcWithParameters " & Text.From(CustomerKey) & ", " & Text.From(GeographyKey)​

 

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

The error tells you exactly what the issue is.

 

If you want IDs as part of your query string, they need to be in text format. So you have two options

  1. Define the parameters as text-valued rather than numbers.
  2. Convert the number to text in your query.

 

"EXECUTE TestProcWithParameters " & Text.From(CustomerKey) & ", " & Text.From(GeographyKey)​

 

Anonymous
Not applicable

Thanks. I actually didn't need to change the parameters. Just adding "Text.From" got it to work. I'll see if I need to change them as I build the visuals.

Sorry if I wasn't clear. I gave two options that you could pick from. You don't need to do both. Just go with whatever makes more sense in your use case.

Anonymous
Not applicable

Ah, ok. Not a problem. The other solution may come in handy at some point in the future.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors