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
KavyaReddy
Regular Visitor

Can we get data from SQL functions

I need get the data to power bi using SQl functions 

 

Is there any way to do this?

 

Thanks

2 ACCEPTED SOLUTIONS
kushanNa
Super User
Super User

hi @KavyaReddy 

 

Yes you should be able to get data from SQL function ,

 

I did a test and I was able to get data from SQL function 

 

following in the test function i have created 

 

kushanNa_0-1744721667708.png

 

and i was able to pull data using that function using the SQL server database get data connector 

 

kushanNa_1-1744721742916.png

 

View solution in original post

rosha_rosha
Resolver II
Resolver II

Hi ,

Yes, you can get data into Power BI using SQL functions by connecting Power BI to your database and using SQL queries (including functions) in your data import process. Here's how you can do it:

1. Connect Power BI to Your Database

  • Open Power BI Desktop.

  • Click on Home > Get Data > SQL Server (or another database type like MySQL, PostgreSQL, etc., depending on your data source).

  • Enter the server name and database details, and select DirectQuery or Import mode.

2. Use SQL Queries to Pull Data

  • After connecting, you can choose to run a SQL query to get your data.

  • Instead of selecting tables directly, click on Advanced options and enter your SQL query with any functions you want to use.

Example:

                 SELECT
                          MyColumn,
                          dbo.MySQLFunction(MyColumn) AS FunctionResult
                          FROM dbo.MyTable

3. Using Stored Procedures or Views

  • You can also use stored procedures or views in your SQL query to encapsulate the SQL functions, allowing you to run complex logic before pulling the data into Power BI.

  • When connecting, instead of selecting a table, you can execute a stored procedure that returns the data you need.

If the solution works for you, accept it as the solution. Let me know if you need any further help!

View solution in original post

3 REPLIES 3
rosha_rosha
Resolver II
Resolver II

Hi ,

Yes, you can get data into Power BI using SQL functions by connecting Power BI to your database and using SQL queries (including functions) in your data import process. Here's how you can do it:

1. Connect Power BI to Your Database

  • Open Power BI Desktop.

  • Click on Home > Get Data > SQL Server (or another database type like MySQL, PostgreSQL, etc., depending on your data source).

  • Enter the server name and database details, and select DirectQuery or Import mode.

2. Use SQL Queries to Pull Data

  • After connecting, you can choose to run a SQL query to get your data.

  • Instead of selecting tables directly, click on Advanced options and enter your SQL query with any functions you want to use.

Example:

                 SELECT
                          MyColumn,
                          dbo.MySQLFunction(MyColumn) AS FunctionResult
                          FROM dbo.MyTable

3. Using Stored Procedures or Views

  • You can also use stored procedures or views in your SQL query to encapsulate the SQL functions, allowing you to run complex logic before pulling the data into Power BI.

  • When connecting, instead of selecting a table, you can execute a stored procedure that returns the data you need.

If the solution works for you, accept it as the solution. Let me know if you need any further help!

kushanNa
Super User
Super User

hi @KavyaReddy 

 

Yes you should be able to get data from SQL function ,

 

I did a test and I was able to get data from SQL function 

 

following in the test function i have created 

 

kushanNa_0-1744721667708.png

 

and i was able to pull data using that function using the SQL server database get data connector 

 

kushanNa_1-1744721742916.png

 

lbendlin
Super User
Super User

Please provide a more detailed explanation of what you are aiming to achieve. What have you tried and where are you stuck?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.