+ Reply to Thread
Results 1 to 6 of 6

Power query code and use of the hash

  1. #1
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    625

    Power query code and use of the hash

    Hi,
    I've been trying to understand M code ( a bit ), and have found if i rename a step, when it is first referred to in the new step it doesn't need a # or quote marks.

    Table.AddColumn(NoHash, "ColumName", each List.FirstN(#"NoHash"[Number],4))

    or;

    Table.AddColumn( EnterInFormBar, "NewColumn", each List.Sum(List.FirstN(#"EnterInFormBar"[Number],[Index])))

    but when the name follows a functiion it does need the hash and double quotes.
    I'd just like to know why one does need # and quotes and the other doesn't.

    I've attached the table I've been playing around with. Any explanations or advice /help / book or website recommendations much appreciated.


    Richard.
    Attached Files Attached Files
    Last edited by Dicken; 12-14-2021 at 12:31 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,257

    Re: Power query code and use of the hash

    Neither of those require the hash and quotes since they don't contain spaces or other special characters.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    625

    Re: Power query code and use of the hash

    Hi Rory,
    So to be clear, are you saying the # is only necessary when there are spaces, and has nothing to do with indicating a previous step. ?

    I don't think this correct, I have just tried removing the has form

    Table.AddColumn(NoHash, "FirstFour", each List.FirstN(#"NoHash"[Number],4))

    Thus

    Table.AddColumn(NoHash, "FirstFour", each List.FirstN("NoHash"[Number],4))

    and it now returns an error.

    Richard.
    Last edited by Dicken; 12-15-2021 at 10:23 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,257

    Re: Power query code and use of the hash

    Remove the quotes too:

    Table.AddColumn(NoHash, "FirstFour", each List.FirstN(NoHash[Number],4))

  5. #5
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    625

    Re: Power query code and use of the hash

    Ah, right, now it works.

    RD.

    Thanks, so just to clarify if the hash only necessary when you have a space a bit like single quotes when using 'indirect' or something.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,257

    Re: Power query code and use of the hash

    Similar principle, yes. It's not just spaces - other special items like keywords and operators need the same treatment.

+ 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. VB Code to Read Parameters into Power Query
    By dflak in forum Tips and Tutorials
    Replies: 1
    Last Post: 07-04-2021, 01:22 PM
  2. Code to change Power Query source and refresh
    By kersplash in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-23-2021, 07:35 AM
  3. Power Query - Column Code Help
    By girltoni in forum Excel General
    Replies: 1
    Last Post: 10-07-2020, 02:24 PM
  4. [SOLVED] Power Query - excel formula translation into Power Query
    By afgi in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 02-19-2020, 03:38 AM
  5. Replies: 4
    Last Post: 02-17-2020, 06:03 AM
  6. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM
  7. code to refresh power query not working ..
    By Hassan1977 in forum Excel General
    Replies: 0
    Last Post: 08-31-2016, 12:31 PM

Tags for this Thread

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