+ Reply to Thread
Results 1 to 15 of 15

write SQLs in power query M language

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    write SQLs in power query M language

    Hi Guys,

    this is some kind of continuity from here:

    https://www.excelforum.com/excel-pro...ml#post4917914

    How to write sql statements in M?

    I want to get :

    Please Login or Register  to view this content.
    so simple sql in power query M language.

    In attachment i addded Vba to create query and and this query to workbook for PQ.
    Now time for SQL code for this...

    Please help,
    Best,
    Jacek
    Attached Files Attached Files

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: write SQLs in power query M language

    You don't write SQL in M. You load the two tables into PQ, then merge them in a query.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: write SQLs in power query M language

    yes xlitnitwit.

    But PQ is using M language where you can do all things line in normal SQL.
    So within Let and In you can write a code for this ;-)

    Best,
    Jacek

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: write SQLs in power query M language

    Half the point of using PQ is that it has a user interface to do that for you!

    I was also just coming back to amend my earlier post, since if you are using ODBC you can pass SQL queries using the Odbc.Query() function to extract just the source data you want.

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: write SQLs in power query M language

    Half the point of using PQ is that it has a user interface to do that for you!
    agree

    I was also just coming back to amend my earlier post, since if you are using ODBC you can pass SQL queries using the Odbc.Query() function to extract just the source data you want.
    Odbc.query will create listobjects from odbc source yes?
    So will create query and recordset will be odbc recordset?
    Best,
    Jacek
    Last edited by jaryszek; 06-14-2018 at 06:18 AM.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: write SQLs in power query M language

    Quote Originally Posted by jaryszek View Post
    Odbc.query will create listobjects from odbc source yes?
    Assuming you choose to load the data to a table, yes.

  7. #7
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: write SQLs in power query M language

    I am thinking how it can help me with power query.

    I will create ODBC connection and set recordset.
    And next i will set ODBC.query() to power query.

    So SQL only i should perform using ODBC connections.

    It is a pity that Power Query has no possibilty to write normal sqls - it would be awesome!

    Best,
    Jacek

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: write SQLs in power query M language

    Quote Originally Posted by jaryszek View Post
    It is a pity that Power Query has no possibilty to write normal sqls - it would be awesome!
    Why? What are you trying to do that you can't do with PQ?

  9. #9
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: write SQLs in power query M language

    SELECT t_current.*
    FROM t_current LEFT JOIN t_previous ON t_current.Order= t_previous.Order
    WHERE t_previous.Order Is Null
    I am trying to write left join there.

    And create variables for fields and records.

    Best,
    Jacek

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: write SQLs in power query M language

    Quote Originally Posted by jaryszek View Post
    I am trying to write left join there.
    You can do that when merging two tables.

    And create variables for fields and records.
    I don't know what you mean by that as regards PQ. Can you be more specific?

  11. #11
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: write SQLs in power query M language

    Thank you,

    where can i add where clause to it?

    And create variables for fields and records.
    I mean that i have to have universal code for each comparing tables.
    One time i will have 3 columns within table and sometimes 10.

    So macro will have to loop through each table, add to PQ, merge them using joins.

    So knowing M language here to create your commands is very important, manually i can do only sql join here for one table.

    Best,
    Jacek

  12. #12
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: write SQLs in power query M language

    Quote Originally Posted by jaryszek View Post
    where can i add where clause to it?
    You use filters.

    I mean that i have to have universal code for each comparing tables.
    One time i will have 3 columns within table and sometimes 10.

    So macro will have to loop through each table, add to PQ, merge them using joins.

    So knowing M language here to create your commands is very important, manually i can do only sql join here for one table.
    Good luck. I only have 2010 here, which does not expose PQ.

  13. #13
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: write SQLs in power query M language

    Thank you,
    anyone know M language?

    Best,
    Jacek

  14. #14
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: write SQLs in power query M language

    Why do you need it (there are reference documents available online)? If you do it manually in the UI, PQ will write the M code for you. Assuming you have programmatic access to the M code, you can then amend that as needed.

  15. #15
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: write SQLs in power query M language

    Hi xlnitwit,

    Yes, i can record macro and show what code is for this.
    But first of all i have to create good queries ;-) And learn how to do it within power query.

    Best,
    Jacek

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sub-Forum for Power Query & Power BI?
    By AliGW in forum Suggestions for Improvement
    Replies: 7
    Last Post: 08-26-2018, 05:25 PM
  2. [SOLVED] formula on power query (M language)
    By pccamara in forum Access Tables & Databases
    Replies: 3
    Last Post: 06-11-2018, 05:16 AM
  3. Replies: 0
    Last Post: 04-05-2018, 01:16 AM
  4. error in power query & power pivot
    By Baldev Kumar in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 01-03-2018, 01:34 AM
  5. Help make my Excel formula work in Power Pivot / Dax language
    By Paul Reins in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-10-2013, 03:27 PM
  6. [SOLVED] How to write a language independent formula
    By Jaime Stuardo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-30-2005, 09:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1