Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

Dynamic parameter value

Hello all,   I have 3 parameters in place to pull data from Google Analytics once I open my template   The code looks like that   let Source = GoogleAnalytics.Accounts(), #"GA Account" ...
  • Anonymous's avatar
    Anonymous
    9 years ago

    I managed to found a solution. Below is the code that made it happen. Now I can successfully pull the value of the cell based on my parameter selection. This allows me to download data from Google Analytics once the template loads. This is great if you have lots of different sites but you want to use a master template.

     

    let
        Source = GoogleAnalytics.Accounts(),
        
        ChangeDataTypes = Table.TransformColumnTypes(
                                            xClients,
                                            {{"GA Account ID", Text.Type}, 
                                             {"GA Property ID", Text.Type}, 
                                             {"GA View ID", Text.Type}}),
        
        AccountID= ChangeDataTypes{0}[GA Account ID],
        PropertyID = ChangeDataTypes{0}[GA Property ID],
        ViewID = ChangeDataTypes{0}[GA View ID],
    
    
        #"GA Account" = Source{[Id=AccountID]}[Data],
        #"GA Property" = #"GA Account"{[Id=PropertyID]}[Data],
        #"GA View" = #"GA Property"{[Id=ViewID]}[Data],
        #"Added Items" = Cube.Transform(#"GA View", {{Cube.AddAndExpandDimensionColumn, "ga:channelGrouping", {"ga:channelGrouping"}, {"Default Channel Grouping"}}, {Cube.AddAndExpandDimensionColumn, "ga:country", {"ga:country"}, {"Country"}}, {Cube.AddAndExpandDimensionColumn, "ga:date", {"ga:date"}, {"Date"}}, {Cube.AddMeasureColumn, "Avg. Session Duration", "ga:avgSessionDuration"}, {Cube.AddMeasureColumn, "Bounce Rate", "ga:bounceRate"}, {Cube.AddMeasureColumn, "Session Duration", "ga:sessionDuration"}, {Cube.AddMeasureColumn, "Sessions", "ga:sessions"}})
    in
        #"Added Items"