cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Fill column with SQL Server Function

Hi,

 

for my problem I found this:

https://community.powerbi.com/t5/Desktop/SQL-Functions-in-Power-BI/m-p/235426#M104804

 

But it seems, it is no longer working.

 

As Source I have a SQL table, I only use 2 columns from it.: ordID and oLineID

Next I want to add a custom column: color 

with gets its value from a SQL Server Function with Parameters ordID and oLineID.

 

First Step:

ordIDoLineID
3099841278640
3099851278641
3099871278645


How it should look final like this:

ordIDoLineIDcolor 
3099841278640green
3099851278641blue
3099871278645yellow

 

This is the SQL Server Function:

CREATE FUNCTION MAU_BI.fnGetFarbe
(
@ordID int,
@oLineID int
)
RETURNS nvarchar(max)
AS
BEGIN

DECLARE @strReturn nvarchar(255)

select @strReturn = ( select optDescription
from Product.Options

inner join OrderLineOptions on OrderLineOptions.optID = Product.Options.optID and optoID = 4
inner join OrderLines ol on ol.oLineID = OrderLineOptions.oLineID
where ol.ordID = @ordID and ol.olnID = @oLineID)

RETURN(@strReturn);
END

 

It was working a few years back, so it should still work. I was a shame, the M Source was not included in the original post.

 

 

Sven

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User V
Super User V

Re: Fill column with SQL Server Function

Hi @SvenUngerecht ,

 

You can create a query calling this SQL Function and transform it in a Power Query Function. After that just invoke this new power query function in your table passing both parameters.

 

This link can help you:

https://eriksvensen.wordpress.com/2020/04/29/powerquery-using-sql-scalar-value-functions-in-powerque...



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

2 REPLIES 2
Highlighted
Super User V
Super User V

Re: Fill column with SQL Server Function

Hi @SvenUngerecht ,

 

You can create a query calling this SQL Function and transform it in a Power Query Function. After that just invoke this new power query function in your table passing both parameters.

 

This link can help you:

https://eriksvensen.wordpress.com/2020/04/29/powerquery-using-sql-scalar-value-functions-in-powerque...



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

Highlighted
Regular Visitor

Re: Fill column with SQL Server Function

All I need to do, was to remove the last step where the function is invoked. Arg........

Helpful resources

Announcements

August Community Highlights

Check out a full recap of the month!

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Kudoed Authors