Forum Discussion

chriswragge's avatar
chriswragge
Helper I
8 years ago
Solved

Create multiple tables from single query

Hi there,   I have 20 differing queries all essentially referencing the same basic code.   = #"Base Code - New"(startDateNew, endDateNew, "at") "Base Code - New" is a function that takes in 3 va...
  • MFelix's avatar
    MFelix
    8 years ago

    Hi chriswragge,

     

    As it is refered in the links I provided you can do a single query that is transformed in a function on that function you need to refer to a variable (identified as (something) => )

     

    Then adding a table with all the variable you need to change alonside with the custom functions you will get a single querie and not 20.

     

    See attach an example with a webpage change.

     

     

    Custom Function

     

    (page) =>
    
    let
        Source = Web.Page(Web.Contents("https://editorial.rottentomatoes.com/guide/200-essential-movies-to-watch-now/" & Number.ToText(page) &"/")),
        Data0 = Source{0}[Data],
        #"Changed Type" = Table.TransformColumnTypes(Data0,{{"Column1", Percentage.Type}, {"Column2", type text}})
    in
        #"Changed Type"

     

     Final Query

    let
        Source = {2..5},
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each WebPage([Column1])),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column1", "Column2"}, {"Custom.Column1", "Custom.Column2"})
    in
        #"Expanded Custom"

    Regards,

    MFelix