This is awesome !!! I just created process to read SharePoint Online Lists and sink the data to the SQL Data Warehouse. I did have to modify the code as I need to run an insert for each row however Text.Combine() was the unsung hero. Passing the sql scripts as one large text tuple set, with a group by transformation. Thanks for explaining this !!!
Good point, Tommy. You can get around this by converting your SQL column to a list and then using the Text.Combine() function to concatenate all of your rows.
@@BIElite Hi,thanks for the tip but it throws me error after list that cannot convert list to type text when i want to insert more than one record.Is it possible to make to more clear how to insert more than 1 record,thanks
fxListGenerate = () => let Source = List.Generate( ()=> [Result= try fxRunSQL(0) otherwise null, x = 0], each [Result] null, each [Result = try fxRunSQL([x]+1) otherwise null, x =[x]+1], each [Result]), #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Expanded Column1" = Table.ExpandTableColumn(your column names), #"Removed Duplicates" = Table.Distinct(#"Expanded Column1", {primary key column}), in #"Removed Duplicates" fxRunSQL = (x as number) => let Source = Sql.Database(server name, database name), INSERT = Value.NativeQuery(Source, #"API Call and INSERT Data"{x}[Custom]) in INSERT in fxListGenerate Although it works, it isn't very efficient because it just selects all tables, combines them and then removes the duplicates. Now that I saw this, I'm going to try Parker's advice.
Hi, thank you so much for this. I can get the query to run, however it only runs for the first row in my dataset. Do you know how to get the Native query to run for each row in the dataset?
In case anyone comes across this, I've got it: Instead of right clicking and drilling down on the column, add this line of M code after the AddSQLColumn part: SQL = Text.Combine(#"Added Custom"[SQL],"#(lf)")
This is very useful. 😲 1 question. In this example, you are writing back the data as part of a scheduled refresh process. Can it be done in a non-scheduled manner (i.e., the user opens the dashboard at her own convenient time, and wants to write certain data back to SQL through Power BI). Is this possible?
Really interesting question. Yes, definitely. Don't set this up for scheduled refresh, and instead just refresh the dataset manually. If your end user doesn't have access to the workspace, you can leverage Power Automate to refresh the dataset via button click in your Power BI report.
Hi! this is very useful solution. BTW which of the dataset is your source for the raport? As I know there is no possibility to use multiple datasets for one report.
@@BIElite I have understood that you have build three datasets 'DataInsert No 1,2,3' to insert data into a data base. Is your report refreshed once per hour as well? How are you able to connect three datasets to one report.
I'm not sure how this performance would look with scale. I imagine someone can come up with some better SQL to check if the record already exists, and then this should work ok.
Thanks for the video! Amazing. One quick question: I have created a dataflow in power bi. A colleague of mine needs this dataflow to feed its PIMS. Is there I way I can pass her this dataflow? Let's say like exporting this dataflow to MySQL? Your Idea will be much appreciated. Thanks.
i have multiple row to insert , it can work with text combine the list , but i got error if the data has single quotation mark in the text. any advice ?
Hello, and thanks for the video, but I'm looking to change a value in the table, give the user to privilege to click and modify the Value in the table, and updating it where it should reflect back to the SQL/Oracle Database.
Hi, this is great. is there a way to do the same against oracle database? I get error ORA-00933 while running several sql statements in one value.nativequery. thx in advance
When I'm using INSERT I'm getting error i.e. Expression.Error: We cannot convert a value of type Table to type Text. Could you please suggest correct solution? Thanks in advance!
I had same problem, you need to turn AddSQL column to list and then use Text.Combine with space as separator. After that it works. AddSQLColumn = Text.Combine(#"Changed Type"[AddSQLColumn]," ")
@@didijaba After the AddSQLColumn step, I turned my SQL Column into a list. So does the Text.Combine step come in after I turn the SQL Column into a list? And what text am I combining?
Has anyone tried this and works in the Desktop but not in the service? I have an example that works fine in both sides but a new report I am working on is writing to SQL from the Desktop but not in the service, so just checking if we know of any limitations on doing this?
Hi Parker, awesome video tried it out but got stuck on the Drill Down part as the values are not changing for new records, was only able to insert the one record. How can I get it to work?
Just want to call out to be very careful with doing any type of INSERT/UPDATE/etc... within Power Query. In the video he had a check to make sure to not insert if it already exists which is good. the statement can run one or more times - which could lead to problems. Be very very careful. 🙏
UPDATED: See this video for a better technique to write back multiple rows: ruclips.net/video/WgIhsF7kEjI/видео.html
Great info. Tried to look for a simple explanation of Power BI data to SQL Server and you've done it! Thanks 🙂
This is awesome !!! I just created process to read SharePoint Online Lists and sink the data to the SQL Data Warehouse. I did have to modify the code as I need to run an insert for each row however Text.Combine() was the unsung hero. Passing the sql scripts as one large text tuple set, with a group by transformation. Thanks for explaining this !!!
Hey Danny, I'm very interested in the steps you did for this. This is exactly what I'm trying to do now :). Thanks for letting me know it's possible
I was literally trying to do this using workaround R script (which I'm not good at). I can't believe this is so easy.... Thank you for your video!
Good to hear, Jon! I've also tried with Python and R lol
@@BIElite have you found any performance difference?
Amazing. This approach enable the usage of Power Query to one of the most useful cases of ETL. Thanks!
I agree! It's lightweight and free.
Wow, this is very eyes-opening. I am wondering how we can insert multiple values at the same time? The drill down took only one row at a time.
Good point, Tommy. You can get around this by converting your SQL column to a list and then using the Text.Combine() function to concatenate all of your rows.
@@BIElite Hi,thanks for the tip but it throws me error after list that cannot convert list to type text when i want to insert more than one record.Is it possible to make to more clear how to insert more than 1 record,thanks
its will be great to know how can we insert to sql more than 1 row
@@noyraz indeed ,looking forward for it😉
I did it like this:
let
fxListGenerate = () =>
let
Source = List.Generate( ()=>
[Result= try fxRunSQL(0) otherwise null, x = 0],
each [Result] null,
each [Result = try fxRunSQL([x]+1) otherwise null, x =[x]+1],
each [Result]),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandTableColumn(your column names),
#"Removed Duplicates" = Table.Distinct(#"Expanded Column1", {primary key column}),
in
#"Removed Duplicates"
fxRunSQL = (x as number) =>
let
Source = Sql.Database(server name, database name),
INSERT = Value.NativeQuery(Source, #"API Call and INSERT Data"{x}[Custom])
in
INSERT
in
fxListGenerate
Although it works, it isn't very efficient because it just selects all tables, combines them and then removes the duplicates.
Now that I saw this, I'm going to try Parker's advice.
What a mastermind trick Parker you show..
Millions Thanks
WOOW! This is Pure Gold! Thanks for sharing ! I'm already thinking of at least two use-cases I have:)
Great to hear, Cristian! I'm looking for other datasets to use this for as well.
Hi, thank you so much for this. I can get the query to run, however it only runs for the first row in my dataset. Do you know how to get the Native query to run for each row in the dataset?
In case anyone comes across this, I've got it: Instead of right clicking and drilling down on the column, add this line of M code after the AddSQLColumn part: SQL = Text.Combine(#"Added Custom"[SQL],"#(lf)")
This is very useful. 😲 1 question. In this example, you are writing back the data as part of a scheduled refresh process. Can it be done in a non-scheduled manner (i.e., the user opens the dashboard at her own convenient time, and wants to write certain data back to SQL through Power BI). Is this possible?
Really interesting question. Yes, definitely. Don't set this up for scheduled refresh, and instead just refresh the dataset manually. If your end user doesn't have access to the workspace, you can leverage Power Automate to refresh the dataset via button click in your Power BI report.
Hi! this is very useful solution. BTW which of the dataset is your source for the raport? As I know there is no possibility to use multiple datasets for one report.
Dzień dobry Michał! Not sure exactly what you mean in this question. Could you elaborate?
@@BIElite I have understood that you have build three datasets 'DataInsert No 1,2,3' to insert data into a data base. Is your report refreshed once per hour as well? How are you able to connect three datasets to one report.
Can we use this approach with sap data sources ?
Interesting! Why would you not use MS Flow for this?
Is it possible to writeback dax measure to sql server?
Very very helpful Thank you
how did you do it can you share with me , thank you
Interesting .. would this be adaptable for a medium size table to be written back to SQL?
I'm not sure how this performance would look with scale. I imagine someone can come up with some better SQL to check if the record already exists, and then this should work ok.
@@BIElite I was thinking more on a flush and fill technique, definitely something to try. Thank you!
Do you know how I can expand this to multiple rows on a tabel? Currently only getting 1 row to write when I need it to look through a number of rows.
Hi Zachary, see my latest video from today! It shows how to insert multiple records in a SQL db.
Which statement actually pulls data from the API data source
Woa can be this done with sharepoint list? or excel?
Yes it can! Any data source will work.
@@BIElite Oh really? is it the same process? isn't it? thank you very much
This is fantastic, thank you! :)
Thanks for the video! Amazing. One quick question: I have created a dataflow in power bi. A colleague of mine needs this dataflow to feed its PIMS. Is there I way I can pass her this dataflow? Let's say like exporting this dataflow to MySQL? Your Idea will be much appreciated. Thanks.
This is a good one! Thank you Parker!
No problem! Thanks for the comment
I'm using Oracle as a database and I get errors like this "Native queries aren't supported by this value."
any suggestion?
Hey did you get any solution for this error?
Hi, How do we do it if we have 1000 rows in a dataset table.
Wonderful, its a very helpful Idea, Thanks a lot
Hi. Does anyone know if you can write to a SQL db from a power BI report that has been published to a workspace?
Hi Parker,
How can I delete the current SQL Table before and then bulk insert all the data from Power Query ?
Please help..!!
Hey Parker, thanks a lot for this video! Very informative.
This is great! However it only works in Import data mode
can you share this Power Bi file please for reference?
Great video, just a question : does this work with MS Access database
Not totally sure, but you might be able to test it fairly quickly!
i have multiple row to insert ,
it can work with text combine the list ,
but i got error if the data has single quotation mark in the text.
any advice ?
Thanks!!! It's amazing!
Hello, and thanks for the video, but I'm looking to change a value in the table, give the user to privilege to click and modify the Value in the table, and updating it where it should reflect back to the SQL/Oracle Database.
I need this too, is there any way a user could do an entry, and to push this value back to the DB?
Thanks.
this is crazy good!!! thanks alot!
No problem, Peter!
It's really cool and amazing! Excellent tips
Hi, this is great. is there a way to do the same against oracle database? I get error ORA-00933 while running several sql statements in one value.nativequery. thx in advance
When I'm using INSERT I'm getting error i.e. Expression.Error: We cannot convert a value of type Table to type Text.
Could you please suggest correct solution? Thanks in advance!
I had same problem, you need to turn AddSQL column to list and then use Text.Combine with space as separator. After that it works.
AddSQLColumn = Text.Combine(#"Changed Type"[AddSQLColumn]," ")
@@didijaba After the AddSQLColumn step, I turned my SQL Column into a list. So does the Text.Combine step come in after I turn the SQL Column into a list? And what text am I combining?
@@samwong777 #"Create SQL expression" = Table.AddColumn(#"Changed Type3", "AddSQLColumn", each "IF EXISTS (SELECT * FROM tblHops_SatnoOpterecenje WITH (UPDLOCK) WHERE tblHops_SatnoOpterecenje_ID = '" & [tblHops_SatnoOpterecenje_ID] & "')#(lf)SELECT * FROM tblHops_SatnoOpterecenje#(lf)ELSE INSERT INTO tblHops_SatnoOpterecenje (DatumOpterecenja,Sat,Plan_MWh_Per_h, Ostvarenje_MWh_Per_h, tblHops_SatnoOpterecenje_ID) VALUES ('" & [DatumOpterecenja] & "','" & [Sat] & "'," & [Plan_MWh_Per_h] & "," & [Ostvarenje_MWh_Per_h] & ", '" & [tblHops_SatnoOpterecenje_ID] & "')#(lf)SELECT * FROM tblHops_SatnoOpterecenje"),
#"Changed Type of SQL expression column" = Table.TransformColumnTypes(#"Added Custom4", {{"Create SQL expression", type text}}),
AddSQLColumn = Text.Combine(#"Changed Type5"[AddSQLColumn]," "),
Source3 = Sql.Database("server.xxxxxxx,12314", "NameOfDB"),
INSERT = if Text.Length(AddSQLColumn)> 1 then Value.NativeQuery(Source3, AddSQLColumn) else Table.TransformColumnTypes(#table({"A"},{{0}}), {{"A", type text}})
in
INSERT
Amazing! Thanks a lot!
No problem Jasa!
Ah-Mazing! 😲 Thank you, Parker!
Haha thanks Hachi!
Has anyone tried this and works in the Desktop but not in the service? I have an example that works fine in both sides but a new report I am working on is writing to SQL from the Desktop but not in the service, so just checking if we know of any limitations on doing this?
Hi Parker, awesome video tried it out but got stuck on the Drill Down part as the values are not changing for new records, was only able to insert the one record. How can I get it to work?
Yes, Same case goes with me.
Yes, same here. James, were you able to find out how to get around this?
@@Rafian1924 same here, were you able to find out how to get around this?
@@yoismelperez2744 nope I was not.
@@jcmv007 I just did. Need to use Result = Text.Combine(AddSQLColumn, " ") right after creating the list
How to insert the values to sql database, if we have mutliple records to be inserted?
You would need to employ some logic to group the rows together instead of drilling down into the value like I do in the video.
Nice Tip Man! thanks
No problem Jorge!
Fantastic tip, thank you 🙂
No problem, Muhammad!
Thanks Sir
Thanks for the video.
BTW: That's true "How to lie with statistics" classic in the first pic (showing 1,3 M to ... 1,3 M views) 😂
Scale could have been better for sure!
Just want to call out to be very careful with doing any type of INSERT/UPDATE/etc... within Power Query. In the video he had a check to make sure to not insert if it already exists which is good. the statement can run one or more times - which could lead to problems. Be very very careful. 🙏
Hi Adam, thanks for the input. I tried to make this point clear in the video.
Will the source sata will get affected if we write insert/update in power query?
Interesting!
missed SQL double check
Like it, but looks so complicated...
норм 🙈
This is awfully hacky for something you can do with a stored procedure and an SQL job.
how did you do it can you share with me , thank you