Power BI - Write Data to SQL

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.พ. 2025
  • UPDATED: See this video for a better technique to write back multiple rows: • BULK Write Back to SQL...
    In this Power BI tutorial, learn how to write your data back to a SQL database! I will show you how to query a web API and then store the results in a SQL Server database which you can then report off of! You can even set up multiple datasets on scheduled refresh to push your data to SQL every hour or even every 30 minutes!
    Elite Power BI Consulting:
    bielite.com
    To enroll in my introductory or advanced Power BI courses:
    training.bieli...
    Connect with me on Twitter!
    / powerbielite

ความคิดเห็น • 99

  • @BIElite
    @BIElite  3 ปีที่แล้ว +1

    UPDATED: See this video for a better technique to write back multiple rows: th-cam.com/video/WgIhsF7kEjI/w-d-xo.html

  • @MTUK1981
    @MTUK1981 ปีที่แล้ว +1

    Great info. Tried to look for a simple explanation of Power BI data to SQL Server and you've done it! Thanks 🙂

  • @dannyaguirre2309
    @dannyaguirre2309 4 ปีที่แล้ว +2

    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 !!!

    • @MacPaulos
      @MacPaulos 4 ปีที่แล้ว

      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

  • @JackOfTrades12
    @JackOfTrades12 5 ปีที่แล้ว +2

    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!

    • @BIElite
      @BIElite  5 ปีที่แล้ว +1

      Good to hear, Jon! I've also tried with Python and R lol

    • @JackOfTrades12
      @JackOfTrades12 5 ปีที่แล้ว

      @@BIElite have you found any performance difference?

  • @thiagofraletti4220
    @thiagofraletti4220 4 ปีที่แล้ว +1

    Amazing. This approach enable the usage of Power Query to one of the most useful cases of ETL. Thanks!

    • @BIElite
      @BIElite  4 ปีที่แล้ว

      I agree! It's lightweight and free.

  • @cristian.angyal
    @cristian.angyal 5 ปีที่แล้ว +4

    WOOW! This is Pure Gold! Thanks for sharing ! I'm already thinking of at least two use-cases I have:)

    • @BIElite
      @BIElite  5 ปีที่แล้ว +1

      Great to hear, Cristian! I'm looking for other datasets to use this for as well.

  • @nehashahpatel1741
    @nehashahpatel1741 4 ปีที่แล้ว +1

    What a mastermind trick Parker you show..
    Millions Thanks

  • @tommynguyen4253
    @tommynguyen4253 5 ปีที่แล้ว +5

    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.

    • @BIElite
      @BIElite  5 ปีที่แล้ว +2

      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.

    • @brijendraydv
      @brijendraydv 5 ปีที่แล้ว +3

      @@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

    • @noyraz
      @noyraz 5 ปีที่แล้ว +1

      its will be great to know how can we insert to sql more than 1 row

    • @brijendraydv
      @brijendraydv 5 ปีที่แล้ว

      @@noyraz indeed ,looking forward for it😉

    • @DreeKun
      @DreeKun 5 ปีที่แล้ว +1

      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.

  • @louism.4980
    @louism.4980 ปีที่แล้ว

    This is fantastic, thank you! :)

  • @saadnageeb4633
    @saadnageeb4633 2 ปีที่แล้ว

    Wonderful, its a very helpful Idea, Thanks a lot

  • @rakeshnag70
    @rakeshnag70 4 ปีที่แล้ว

    Can we use this approach with sap data sources ?

  • @tenaciousdata9200
    @tenaciousdata9200 5 ปีที่แล้ว +2

    This is a good one! Thank you Parker!

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      No problem! Thanks for the comment

  • @deniseyu9015
    @deniseyu9015 2 ปีที่แล้ว

    It's really cool and amazing! Excellent tips

  • @Bananathan25
    @Bananathan25 3 ปีที่แล้ว +1

    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?

    • @Bananathan25
      @Bananathan25 3 ปีที่แล้ว +4

      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)")

  • @sonhuynhtien4744
    @sonhuynhtien4744 3 ปีที่แล้ว

    how did you do it can you share with me , thank you

  • @michamuszynski6832
    @michamuszynski6832 5 ปีที่แล้ว +1

    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
      @BIElite  5 ปีที่แล้ว

      Dzień dobry Michał! Not sure exactly what you mean in this question. Could you elaborate?

    • @michamuszynski6832
      @michamuszynski6832 5 ปีที่แล้ว

      @@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.

  • @kirisko3067
    @kirisko3067 4 ปีที่แล้ว +1

    Very very helpful Thank you

  • @roxanarodriguez1828
    @roxanarodriguez1828 4 ปีที่แล้ว +1

    Woa can be this done with sharepoint list? or excel?

    • @BIElite
      @BIElite  4 ปีที่แล้ว

      Yes it can! Any data source will work.

    • @roxanarodriguez1828
      @roxanarodriguez1828 4 ปีที่แล้ว

      @@BIElite Oh really? is it the same process? isn't it? thank you very much

  • @zacharydrake7925
    @zacharydrake7925 3 ปีที่แล้ว +1

    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.

    • @BIElite
      @BIElite  3 ปีที่แล้ว

      Hi Zachary, see my latest video from today! It shows how to insert multiple records in a SQL db.

  • @user-hu7ov6fi9y
    @user-hu7ov6fi9y 4 ปีที่แล้ว

    Hey Parker, thanks a lot for this video! Very informative.

  • @mehulbhatia5469
    @mehulbhatia5469 3 ปีที่แล้ว

    Is it possible to writeback dax measure to sql server?

  • @gabrielkn
    @gabrielkn 5 ปีที่แล้ว +1

    Interesting .. would this be adaptable for a medium size table to be written back to SQL?

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      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.

    • @gabrielkn
      @gabrielkn 5 ปีที่แล้ว

      @@BIElite I was thinking more on a flush and fill technique, definitely something to try. Thank you!

  • @yudhinugrahariyansyah9432
    @yudhinugrahariyansyah9432 4 ปีที่แล้ว

    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 ?

  • @Rafian1924
    @Rafian1924 3 ปีที่แล้ว

    Hi, How do we do it if we have 1000 rows in a dataset table.

  • @plgmgua
    @plgmgua 5 ปีที่แล้ว +2

    this is crazy good!!! thanks alot!

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      No problem, Peter!

  • @HachiAdachi
    @HachiAdachi 5 ปีที่แล้ว +2

    Ah-Mazing! 😲 Thank you, Parker!

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      Haha thanks Hachi!

  • @JonasArnout
    @JonasArnout 4 ปีที่แล้ว

    Interesting! Why would you not use MS Flow for this?

  • @timvollman9017
    @timvollman9017 3 ปีที่แล้ว

    Which statement actually pulls data from the API data source

  • @kaushmat
    @kaushmat 4 ปีที่แล้ว +1

    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?

    • @BIElite
      @BIElite  4 ปีที่แล้ว

      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.

  • @padreloco9733
    @padreloco9733 4 ปีที่แล้ว

    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.

  • @Tegarcahya
    @Tegarcahya 4 ปีที่แล้ว +1

    I'm using Oracle as a database and I get errors like this "Native queries aren't supported by this value."
    any suggestion?

    • @mediocrestuff2783
      @mediocrestuff2783 3 ปีที่แล้ว

      Hey did you get any solution for this error?

  • @shashankjyothi7979
    @shashankjyothi7979 2 ปีที่แล้ว

    Hi. Does anyone know if you can write to a SQL db from a power BI report that has been published to a workspace?

  • @tejasbrahmbatt5344
    @tejasbrahmbatt5344 4 ปีที่แล้ว

    Hi Parker,
    How can I delete the current SQL Table before and then bulk insert all the data from Power Query ?
    Please help..!!

  • @novak2033
    @novak2033 5 ปีที่แล้ว +2

    Amazing! Thanks a lot!

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      No problem Jasa!

  • @hoke73
    @hoke73 4 ปีที่แล้ว

    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

  • @vladimir.v.saveliev
    @vladimir.v.saveliev 4 ปีที่แล้ว +2

    Thanks!!! It's amazing!

  • @RahulNegiworld
    @RahulNegiworld 4 ปีที่แล้ว +1

    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!

    • @didijaba
      @didijaba 4 ปีที่แล้ว

      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]," ")

    • @samwong777
      @samwong777 4 ปีที่แล้ว

      @@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?

    • @didijaba
      @didijaba 4 ปีที่แล้ว +1

      @@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

  • @majdyazigi8185
    @majdyazigi8185 5 ปีที่แล้ว

    Great video, just a question : does this work with MS Access database

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      Not totally sure, but you might be able to test it fairly quickly!

  • @yoismelperez2744
    @yoismelperez2744 3 ปีที่แล้ว

    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?

  • @lohitmm
    @lohitmm 3 ปีที่แล้ว

    can you share this Power Bi file please for reference?

  • @jorgeeduardomoltenimoreno3048
    @jorgeeduardomoltenimoreno3048 5 ปีที่แล้ว +1

    Nice Tip Man! thanks

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      No problem Jorge!

  • @zxuan
    @zxuan 3 ปีที่แล้ว

    This is great! However it only works in Import data mode

  • @jcmv007
    @jcmv007 5 ปีที่แล้ว

    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?

    • @Rafian1924
      @Rafian1924 3 ปีที่แล้ว

      Yes, Same case goes with me.

    • @yoismelperez2744
      @yoismelperez2744 3 ปีที่แล้ว

      Yes, same here. James, were you able to find out how to get around this?

    • @yoismelperez2744
      @yoismelperez2744 3 ปีที่แล้ว

      @@Rafian1924 same here, were you able to find out how to get around this?

    • @jcmv007
      @jcmv007 3 ปีที่แล้ว

      @@yoismelperez2744 nope I was not.

    • @yoismelperez2744
      @yoismelperez2744 3 ปีที่แล้ว +1

      @@jcmv007 I just did. Need to use Result = Text.Combine(AddSQLColumn, " ") right after creating the list

  • @aswin131
    @aswin131 4 ปีที่แล้ว

    How to insert the values to sql database, if we have mutliple records to be inserted?

    • @BIElite
      @BIElite  4 ปีที่แล้ว

      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.

  • @mikapeltokorpi7671
    @mikapeltokorpi7671 5 ปีที่แล้ว

    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) 😂

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      Scale could have been better for sure!

  • @MuhammadBerki
    @MuhammadBerki 5 ปีที่แล้ว +1

    Fantastic tip, thank you 🙂

    • @BIElite
      @BIElite  5 ปีที่แล้ว

      No problem, Muhammad!

  • @MTerkait
    @MTerkait 4 ปีที่แล้ว

    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.

    • @davidlang8101
      @davidlang8101 4 ปีที่แล้ว

      I need this too, is there any way a user could do an entry, and to push this value back to the DB?
      Thanks.

  • @rakeshpanigrahi577
    @rakeshpanigrahi577 4 ปีที่แล้ว

    Thanks Sir

  • @AdamSaxton
    @AdamSaxton 5 ปีที่แล้ว +2

    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. 🙏

    • @BIElite
      @BIElite  5 ปีที่แล้ว +2

      Hi Adam, thanks for the input. I tried to make this point clear in the video.

    • @ertf7777
      @ertf7777 10 หลายเดือนก่อน

      Will the source sata will get affected if we write insert/update in power query?

  • @NikoSuomiUlkoilee
    @NikoSuomiUlkoilee 4 ปีที่แล้ว

    Interesting!

  • @amarnadhgunakala2901
    @amarnadhgunakala2901 4 ปีที่แล้ว

    missed SQL double check

  • @ПавелЛинев-ч7м
    @ПавелЛинев-ч7м 3 ปีที่แล้ว

    норм 🙈

  • @rubenbasco7554
    @rubenbasco7554 2 ปีที่แล้ว

    Like it, but looks so complicated...

  • @Crisicus_01
    @Crisicus_01 3 ปีที่แล้ว

    This is awfully hacky for something you can do with a stored procedure and an SQL job.

  • @ducthinhvu2167
    @ducthinhvu2167 3 ปีที่แล้ว

    how did you do it can you share with me , thank you