Forum Discussion

Jeffery24's avatar
Jeffery24
Icon for Helper I rankHelper I
7 years ago
Solved

Power Query using variables from a specific table column value

Hi,   I currently have a table that is adjusted via some variables based off queries. E.g #"Delivery KPI" is a variable.   #"Added Custom30"= Table.AddColumn(#"Added Custom29", "Delivery KPI Targ...
  • Anonymous's avatar
    Anonymous
    7 years ago

    Jeffery24,

    In your scenario, firstly, choose the referenced column in the MetricsDelivery table and click drill down, then copy the M code of this query to advanced editor of your second query where  you want to add custom column.

    There is an example for your reference.

    let
        Source = GoogleAnalytics.Accounts(),
        #"80056532" = Source{[Id="80056532"]}[Data],
        #"UA-80056532-1" = #"80056532"{[Id="UA-80056532-1"]}[Data],
        #"124765743" = #"UA-80056532-1"{[Id="124765743"]}[Data],
        #"Added Items" = Cube.Transform(#"124765743",
            {
                {Cube.AddAndExpandDimensionColumn, "ga:sessionCount", {"ga:sessionCount"}, {"Count of Sessions"}},
                {Cube.AddAndExpandDimensionColumn, "ga:userType", {"ga:userType"}, {"User Type"}},
                {Cube.AddMeasureColumn, "Users", "ga:users"}
            }),//source code of second query
    
    
    
        Source1 = Excel.Workbook(File.Contents("Foldername\testrow.xlsx"), null, true),
        Sheet1_Sheet = Source1{[Item="Sheet1",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Emp ID", Int64.Type}, {"Emp Name", type text}, {"Salary", Int64.Type}, {"Email", type text}, {"Geo", type text}}),// source code of first query
    
        #"Added Custom" = Table.AddColumn(#"Added Items", "Custom", each #"Changed Type"[Emp ID]{0})//reference the first value of Emp ID column in add custom column step of second query
    in
        #"Added Custom"



    Regard,
    Lydia