+ Reply to Thread
Results 1 to 6 of 6

Power query parameter to select result

Hybrid View

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

    Power query parameter to select result

    Hi, in excel, which I've included, I have a formula to pick out the alphabet, numbers or sprcial characters from a string.
    and the reusult is determined by switch looking to a drop down list,

    I have tried to create this so ;

     Table.AddColumn(Source, "Custom", each let
     ttolist = 
    Text.ToList( [Text] ), alltext  = List.RemoveMatchingItems( ttolist, { "0".."9"} ), 
    numbers = 
    List.RemoveMatchingItems( ttolist, alltext ) , 
    special =  List.RemoveMatchingItems(  List.Transform(  alltext, (A)=> Text.Lower(A)) , {"a".."z"} ) , 
    alpha = List.RemoveMatchingItems( alltext, special) 
    in Text.Combine( special  ))

    but the last part following the in I do not want hard coded I have created a paramer of the options, but this does not work when plugged into
    text.combine, I have attached all this. I think the problem is that it sees the value from the parameter as "text", not referring to the variable,


    I have tried putting it withing the let so simplified ;

     Table.AddColumn(#"Changed Type", "Custom", each let caps  =  Text.Split(  Text.Upper([Text]) ," ") ,
    lower =  Text.Split( [Text], " ") , 
    result = Text.Combine(  selectorparameter  ) 
    in result  )
    but this does not work either? help?

    Richard.
    Attached Files Attached Files
    Last edited by Dicken; 05-21-2024 at 10:40 AM. Reason: Added file for clarity of problem

  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,358

    Re: Power query parameter to select result

    You could just do something like this:

    in Text.Combine( if select = "special" then special else if select = "numbers" then numbers else alpha    )
    Everyone who confuses correlation and causation ends up dead.

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

    Re: Power query parameter to select result

    You could also do something like this:

    = (txt)=> 
    let 
    ADD = 
    let ttolist = 
    Text.ToList( txt ), alltext  = 
    List.RemoveMatchingItems( ttolist, 
    { "0".."9"} ), 
    numbers = 
    List.RemoveMatchingItems( ttolist, alltext ) , 
    special =  List.RemoveMatchingItems( 
     List.Transform(  alltext, (A)=> Text.Lower(A)) , 
    {"a".."z"} ) , 
    alpha = List.RemoveMatchingItems( alltext, special),
    selected = Expression.Evaluate("Text.Combine(" & select & ")", [Text.Combine = Text.Combine, special = special, alpha = alpha, numbers = numbers])
    in selected
    in
       ADD

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

    Re: Power query parameter to select result

    Thanks, the first version I understand, but still not sure about the 'rules' as to using it directly, have not used Expression.Evaliuate,
    but will have a look,
    thanks for the help, would give a rep, but won't let me, I have found your previous help re Record.Field very useful.

    Richard.

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

    Re: Power query parameter to select result

    made a bit of progress on Evaluate, set up something very simple and tried a few things, still not really sure how it works,

    but this does what I expected,

     Table.AddColumn(Source, "Custom", each let 
    adding   = [A] + [B] , 
     times  = [B] * [A] in 
    Expression.Evaluate( Pr, [addcol = adding , multcol = times ] ))
    I kept adding speech marks around the parameter Pr to start with, never used this before thank you.

    Richard.

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

    Re: Power query parameter to select result

    Just as an update I have found that you can use a record,

    so Par = parameter { "a","b","c","d"} ,

    Table.AddColumn(
        #"Changed Type", 
        "Custom", 
        each 
          let
            aone = [One] + [Two], 
            atwo = [One] + [Three], 
            athree = [Two] + [Three], 
            afour = [One] + [Three] + [Two], 
            result = Record.FieldValues(
              Record.SelectFields([a = aone, b = atwo, c = athree, d = afour], par)
            ){0}
          in
            result
      )
    Richard.
    Attached Files Attached Files

+ 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. Power query Custom function / parameter query
    By Dicken in forum Office 365
    Replies: 0
    Last Post: 03-23-2022, 10:41 AM
  2. Parameter Value for Power Query
    By AllisterB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2021, 04:32 AM
  3. Create a Parameter Query for US Stocks in Power Query
    By alansidman in forum Tips and Tutorials
    Replies: 0
    Last Post: 10-24-2020, 06:36 AM
  4. Trying to Create a Power Query Parameter where you can Select Multiple Values
    By nickb123 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-10-2020, 10:12 PM
  5. Updating a Parameter through VBA in Power Query
    By RAC81_12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2020, 09:49 AM
  6. Power Query - Parameter not working
    By vibajajo64 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-20-2018, 01:08 AM
  7. Dynamic Parameter Using Power Query
    By NeedForExcel in forum Excel General
    Replies: 1
    Last Post: 06-16-2016, 02:51 AM

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