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
SerenityNow
New Member

How to change data source for Report from sql view to sql function with parameter

Our reports are connected to sql views but we now need to filter everything and so I have sql functions that accept a parameter.   I've tried going into Advanced Editor to change the source of the tables but can't get it to work.

 

How can I change the tables to pull from sql functions instead of sql views without having to redo the entire dataset?

1 ACCEPTED SOLUTION

My reports come from a view.  So currently, the advanced editor looks like this:

 

let
Source = Sql.Database("tcp:mydb.database.windows.net,1433", "mydb"),
dbo_rbv_UserPresence = Source{[Schema="dbo",Item="rbv_UserPresence"]}[Data]
in
dbo_rbv_UserPresence

 

If I change just the source line to what you suggest:

Source = Sql.Database("tcp:mydb.database.windows.net,1433", "mydb", [Query="SELECT * FROM pbi_UserPresence('new')"]),

 

i get this error:

Expression.Error: The key didn't match any rows in the table.
Details:
    Key=
        Schema=dbo
        Item=rbv_UserPresence
    Table=[Table]

 

I am not familiar with the syntax for Advanced Editor but it must be that Source is getting set twice?

 

If I import the sql function as a new table and look at the advanced editor I get this:

let
    Source = Sql.Database("tcp:mydb.database.windows.net", "mydb"),
    dbo_pbi_UserPresence = Source{[Schema="dbo",Item="pbi_UserPresence"]}[Data],
    #"Invoked Functiondbo_pbi_UserPresence1" = dbo_pbi_UserPresence("new")
in
    #"Invoked Functiondbo_pbi_UserPresence1"

 

So I have tried editing the existing reports to match that and it worked on a simple report.  On reports where I have other steps in the advanced editor (renaming columns for example) then I get the same error about the key not matching rows.

 

[Update]

I just got it to work by using.

 

let
    Source = Sql.Database("tcp:mydb.database.windows.net", "caymus"),
    dbo_pbi_Application = Source{[Schema="dbo",Item="pbi_Application"]}[Data],
    #"Invoked Functiondbo_pbi_Application1" = dbo_pbi_Application("new")
in
    #"Invoked Functiondbo_pbi_Application1"

 

 

Sometimes when I copy it in I get the error about the key.  I think extra spaces or something for some reason are causing an issue because if I delete any other spacing after pasting (even though the syntax checked) it then works.

 

Thanks for helping.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @SerenityNow 

When you connect to sql connector,  you can use the advanced options that you can enter the sql query.

vxinruzhumsft_0-1721703106493.png

You can also refer to the follwing link about it.

Import data from a database using native database query - Power Query | Microsoft Learn

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Correct me if I am wrong, but that is only for new reports.  I want to be able to change existing reports.

Anonymous
Not applicable

Hi @SerenityNow 

In advanced editor, you can change the source code to the following,

 

Source = Sql.Database("xx"(Servername), "xxx"(datebasename), [Query="SELECT * FROM xxx(tablename)"])

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

My reports come from a view.  So currently, the advanced editor looks like this:

 

let
Source = Sql.Database("tcp:mydb.database.windows.net,1433", "mydb"),
dbo_rbv_UserPresence = Source{[Schema="dbo",Item="rbv_UserPresence"]}[Data]
in
dbo_rbv_UserPresence

 

If I change just the source line to what you suggest:

Source = Sql.Database("tcp:mydb.database.windows.net,1433", "mydb", [Query="SELECT * FROM pbi_UserPresence('new')"]),

 

i get this error:

Expression.Error: The key didn't match any rows in the table.
Details:
    Key=
        Schema=dbo
        Item=rbv_UserPresence
    Table=[Table]

 

I am not familiar with the syntax for Advanced Editor but it must be that Source is getting set twice?

 

If I import the sql function as a new table and look at the advanced editor I get this:

let
    Source = Sql.Database("tcp:mydb.database.windows.net", "mydb"),
    dbo_pbi_UserPresence = Source{[Schema="dbo",Item="pbi_UserPresence"]}[Data],
    #"Invoked Functiondbo_pbi_UserPresence1" = dbo_pbi_UserPresence("new")
in
    #"Invoked Functiondbo_pbi_UserPresence1"

 

So I have tried editing the existing reports to match that and it worked on a simple report.  On reports where I have other steps in the advanced editor (renaming columns for example) then I get the same error about the key not matching rows.

 

[Update]

I just got it to work by using.

 

let
    Source = Sql.Database("tcp:mydb.database.windows.net", "caymus"),
    dbo_pbi_Application = Source{[Schema="dbo",Item="pbi_Application"]}[Data],
    #"Invoked Functiondbo_pbi_Application1" = dbo_pbi_Application("new")
in
    #"Invoked Functiondbo_pbi_Application1"

 

 

Sometimes when I copy it in I get the error about the key.  I think extra spaces or something for some reason are causing an issue because if I delete any other spacing after pasting (even though the syntax checked) it then works.

 

Thanks for helping.

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.