Last active
March 10, 2026 20:49
-
-
Save halbuki/c676f0fbf482aac6a1fb845fdddfef88 to your computer and use it in GitHub Desktop.
Excel Lambda functions for Power Query Replacer functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* USE NAMESPACE "Replacer" */ | |
| ReplaceText = LAMBDA(_text, _old, _new, | |
| LET( | |
| Help, TRIM(TEXTSPLIT( | |
| "DESCRIPTION:->Replaces all occurrences of _old with _new in _text\nVERSION:->1.0\nPARAMETERS:->_text as text, _old as text, _new as text", | |
| "->", | |
| "\n" | |
| )), | |
| ErrorMessages, {"_text is not text."; "_old is not text."; "_new is not text."}, | |
| _err1, IF(NOT(ISTEXT(_text)), #VALUE!, FALSE()), | |
| _err2, IF(NOT(ISTEXT(_old)), #VALUE!, FALSE()), | |
| _err3, IF(NOT(ISTEXT(_new)), #VALUE!, FALSE()), | |
| ErrorArray, VSTACK(ISERROR(_err1), ISERROR(_err2), ISERROR(_err3)), | |
| Messages, FILTER(ErrorMessages, ErrorArray, ""), | |
| Result, SUBSTITUTE(_text, _old, _new), | |
| Error, IF(OR(ErrorArray), 3, IF(OR(ISERROR(Result)), 2, 1)), | |
| CHOOSE(Error, Result, Help, Messages) | |
| ) | |
| ); | |
| ReplaceValue = LAMBDA(_value, _old, _new, | |
| LET( | |
| Help, TRIM(TEXTSPLIT( | |
| "DESCRIPTION:->Replaces _value if it equals _old with _new, otherwise returns _value\nVERSION:->1.0\nPARAMETERS:->_value as any, _old as any, _new as any", | |
| "->", | |
| "\n" | |
| )), | |
| ErrorMessages, {""}, | |
| ErrorArray, {}, | |
| Messages, {}, | |
| Result, IF(_value = _old, _new, _value), | |
| Error, IF(OR(ErrorArray), 3, IF(OR(ISERROR(Result)), 2, 1)), | |
| CHOOSE(Error, Result, Help, Messages) | |
| ) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment