+ Reply to Thread
Results 1 to 11 of 11

Power Query Custom replacer function

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

    Power Query Custom replacer function

    Hi,
    Can someone help with information or direct me to post or blog re how the replacer function works in M ,

    I have basic replace value ;

    Please Login or Register  to view this content.
    which can be re written ;

    Please Login or Register  to view this content.
    but to take a stage further and replace based on another column;

    Table.ReplaceValue( Source,
    each [Unit] ,
    each if [Item] = "A" then [Unit] * 10 else [Unit] , Replacer.ReplaceValue, {"Unit"} )

    But I cannot figure how to re write with 'custome replacer' , I have tried various such as ;

    =
    Please Login or Register  to view this content.
    Which I thought item = "A" then z = current valuue * 10 ?

    Richard.
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,887

    Re: Power Query Custom replacer function

    I believe that your issue is that Item is formatted as Text and you cannot multiply 10 times a Text value.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

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

    Re: Power Query Custom replacer function

    True, but it's also text for the 'replace condition' and it works fine, if you change it to number it still does not work.
    my problem is with the syntax for a custom replacer.
    rd,

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,887

    Re: Power Query Custom replacer function

    I mistyped. Unit is a text value and that is what you are trying to multiply by. My apologies for the typo. I formatted the Unit as whole numbers, but it reverts to mix type when you run the Replace code. I think that formatting has to be in the Replace Line of code to make it happen. Not sure how to do that.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,887

    Re: Power Query Custom replacer function

    I tried a different means and it still arrived at the same result that you had.

    Please Login or Register  to view this content.
    I tried changing the format of the Unit field to whole number here and it changes it back to a mixed type when I run the Mcode and there has to be a better way. I still believe it is trying to multiply a value (10) times a text in the Unit column.

    I just tried the following and it worked for me.

    Please Login or Register  to view this content.
    Last edited by alansidman; 12-02-2023 at 02:49 PM.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query Custom replacer function

    You can use:

    Please Login or Register  to view this content.
    Rory

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

    Re: Power Query Custom replacer function

    Thanks, I have not had a chance to try this yet, I can find very little information on this so if you can point in direction of more information
    pleaee do, i've found Rick de Groot has some very interesting / complex examples

    Please Login or Register  to view this content.
    just in case you haven't seen it, most of if over my head.

    Richard.

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

    Re: Power Query Custom replacer function

    Thanks for the suggestion, but i was trying to avoid using the built in replacer function as it seems to have it's limitations.

    Richard.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,887

    Re: Power Query Custom replacer function

    Care to share the limitations?
    i was trying to avoid using the built in replacer function as it seems to have it's limitations

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

    Re: Power Query Custom replacer function

    To deal with a condition over multiple columns, also just type in replacer does not really give much idea as to what it's doing.

    =
    Please Login or Register  to view this content.

    This is the question I asked answer by rory;

    Please Login or Register  to view this content.
    [/CODE]

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

    Re: Power Query Custom replacer function

    Thanks again, yes working through it it and looking it makes perfect sense, how simple everything is once it's been pointed out by someone else.😊

    Richard.

+ 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. [SOLVED] Power Query custom function variable to make table a list
    By Dicken in forum Office 365
    Replies: 10
    Last Post: 07-08-2023, 11:13 AM
  2. How to update a custom function in Power Query
    By MangoFresh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-10-2023, 08:58 AM
  3. Power Query Custom function for running total
    By Dicken in forum Office 365
    Replies: 6
    Last Post: 10-29-2022, 10:58 AM
  4. Power query Custom function / parameter query
    By Dicken in forum Office 365
    Replies: 0
    Last Post: 03-23-2022, 10:41 AM
  5. Replies: 1
    Last Post: 02-14-2022, 06:23 AM
  6. Replies: 1
    Last Post: 11-17-2021, 08:35 AM
  7. Power Query - Invoke Custom Function
    By leukep in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2017, 02:18 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