Power BI - Write Data to SQL

Поделиться
HTML-код
  • Опубликовано: 3 дек 2024
  • НаукаНаука

Комментарии • 99

  • @BIElite
    @BIElite  3 года назад +1

    UPDATED: See this video for a better technique to write back multiple rows: ruclips.net/video/WgIhsF7kEjI/видео.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 4 года назад +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  4 года назад +1

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

    • @JackOfTrades12
      @JackOfTrades12 4 года назад

      @@BIElite have you found any performance difference?

  • @thiagofraletti4220
    @thiagofraletti4220 3 года назад +1

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

    • @BIElite
      @BIElite  3 года назад

      I agree! It's lightweight and free.

  • @tommynguyen4253
    @tommynguyen4253 4 года назад +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  4 года назад +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 4 года назад +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 4 года назад +1

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

    • @brijendraydv
      @brijendraydv 4 года назад

      @@noyraz indeed ,looking forward for it😉

    • @DreeKun
      @DreeKun 4 года назад +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.

  • @nehashahpatel1741
    @nehashahpatel1741 4 года назад +1

    What a mastermind trick Parker you show..
    Millions Thanks

  • @cristian.angyal
    @cristian.angyal 4 года назад +4

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

    • @BIElite
      @BIElite  4 года назад +1

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

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

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

  • @michamuszynski6832
    @michamuszynski6832 4 года назад +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  4 года назад

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

    • @michamuszynski6832
      @michamuszynski6832 4 года назад

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

  • @rakeshnag70
    @rakeshnag70 4 года назад

    Can we use this approach with sap data sources ?

  • @JonasArnout
    @JonasArnout 4 года назад

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

  • @mehulbhatia5469
    @mehulbhatia5469 3 года назад

    Is it possible to writeback dax measure to sql server?

  • @kirisko3067
    @kirisko3067 4 года назад +1

    Very very helpful Thank you

  • @sonhuynhtien4744
    @sonhuynhtien4744 2 года назад

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

  • @gabrielkn
    @gabrielkn 4 года назад +1

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

    • @BIElite
      @BIElite  4 года назад

      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 4 года назад

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

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

  • @timvollman9017
    @timvollman9017 3 года назад

    Which statement actually pulls data from the API data source

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

  • @louism.4980
    @louism.4980 10 месяцев назад

    This is fantastic, thank you! :)

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

  • @tenaciousdata9200
    @tenaciousdata9200 4 года назад +2

    This is a good one! Thank you Parker!

    • @BIElite
      @BIElite  4 года назад

      No problem! Thanks for the comment

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

  • @Rafian1924
    @Rafian1924 3 года назад

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

  • @saadnageeb4633
    @saadnageeb4633 2 года назад

    Wonderful, its a very helpful Idea, Thanks a lot

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

  • @user-hu7ov6fi9y
    @user-hu7ov6fi9y 4 года назад

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

  • @zxuan
    @zxuan 3 года назад

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

  • @lohitmm
    @lohitmm 3 года назад

    can you share this Power Bi file please for reference?

  • @majdyazigi8185
    @majdyazigi8185 4 года назад

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

    • @BIElite
      @BIElite  4 года назад

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

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

  • @vladimir.v.saveliev
    @vladimir.v.saveliev 4 года назад +2

    Thanks!!! It's amazing!

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

  • @plgmgua
    @plgmgua 4 года назад +2

    this is crazy good!!! thanks alot!

    • @BIElite
      @BIElite  4 года назад

      No problem, Peter!

  • @deniseyu9015
    @deniseyu9015 2 года назад

    It's really cool and amazing! Excellent tips

  • @hoke73
    @hoke73 3 года назад

    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

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

  • @novak2033
    @novak2033 4 года назад +2

    Amazing! Thanks a lot!

    • @BIElite
      @BIElite  4 года назад

      No problem Jasa!

  • @HachiAdachi
    @HachiAdachi 4 года назад +2

    Ah-Mazing! 😲 Thank you, Parker!

    • @BIElite
      @BIElite  4 года назад

      Haha thanks Hachi!

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

  • @jcmv007
    @jcmv007 4 года назад

    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.

  • @jorgeeduardomoltenimoreno3048
    @jorgeeduardomoltenimoreno3048 4 года назад +1

    Nice Tip Man! thanks

    • @BIElite
      @BIElite  4 года назад

      No problem Jorge!

  • @MuhammadBerki
    @MuhammadBerki 4 года назад +1

    Fantastic tip, thank you 🙂

    • @BIElite
      @BIElite  4 года назад

      No problem, Muhammad!

  • @rakeshpanigrahi577
    @rakeshpanigrahi577 4 года назад

    Thanks Sir

  • @mikapeltokorpi7671
    @mikapeltokorpi7671 4 года назад

    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  4 года назад

      Scale could have been better for sure!

  • @AdamSaxton
    @AdamSaxton 4 года назад +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  4 года назад +2

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

    • @ertf7777
      @ertf7777 8 месяцев назад

      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

  • @rubenbasco7554
    @rubenbasco7554 Год назад

    Like it, but looks so complicated...

  • @ПавелЛинев-ч7м
    @ПавелЛинев-ч7м 3 года назад

    норм 🙈

  • @Crisicus_01
    @Crisicus_01 3 года назад

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

  • @ducthinhvu2167
    @ducthinhvu2167 2 года назад

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