itsnotaboutthecell

Power Query M - CASE WHEN Statement

Jul 7th, 2018
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. /*
  2. Created By: Alex Powers
  3. Website: http://www.itsnotaboutthecell.com
  4. LinkedIn: https://www.linkedin.com/in/alexmpowers/
  5.  
  6. Concept: Replicate a CASE Statement with wildcards and forced casing options
  7. Instructions: Set Your Lookup Value and Return Value in the Values List
  8. */
  9.  
  10. (#"Input Value" as text, Like as logical, #"Force Case" as logical) as any =>
  11. let
  12.  
  13. Values = {
  14. {"foo", "returnVal"},
  15. {"bar", "returnVal2"}
  16. },
  17. CaseSensitive = if #"Force Case" then #"Input Value" else Text.Lower(#"Input Value"),
  18. Result = if Like then
  19. List.First(List.Select(Values, each Text.Contains(CaseSensitive, _{0}))){1}?
  20. else List.First(List.Select(Values, each _{0} = CaseSensitive)){1}?
  21. in
  22. Result
Advertisement
Add Comment
Please, Sign In to add comment