Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago

List.Average and Select rows

Hello,

could someone help me with this problem?

I am trying to add this formula =List.Average(Table.SelectRows(#"added custom6", each [roles] = _[roles])[wage])

 

I have this table

ROLESWAGE
role110
role111
role210
role25
role35
role38

 

And I want to add third column with that formula, it should do average of every specific role.

It should look like this:

ROLESWAGEAVG WAGE
role11010,5
role11110,5
role2107,5

 

 

But that formula is doing an average of every position, not the specific one... so it look like this..

ROLESWAGEAVG WAGE
role1108,17

role1

118,17
role2108,17

 

14 Replies

  • Anonymous , You should create a meausre in DAX

     

    Measure =

    Average(Table[WAGE])

    • Anonymous's avatar
      Anonymous
      Not applicable

      yeah but it would do the same think that i do not want, right? - making average of all wages, not specified (or i am wrong, i am still beginner)

       

      and I would lke to create it in power query if its possible

  • Hi Anonymous 

    You need to assign the outer ROLE column to a variable like below:

    let
    role = [ROLES]
    in List.Average(Table.SelectRows(#"Changed Type",each [ROLES] = role)[WAGE])

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      In my original table I have roles named like "IT support", "Manager of xxx", "Supervisor"... how should I write it pls?

      • danextian's avatar
        danextian
        Super User
        let
        role = [ROLES]
        in List.Average(Table.SelectRows(#"Changed Type",each [ROLES] = role)[WAGE])

         

        I simply updated this part of your formula with the correct syntax:

        each [roles] = _[roles]

         

        [ROLES] is a column assigned to the role variable. This should be done whenver you're trying to access a column outside the current scope which in this case is #"Changed Type". Whatever the value of ROLES is it will be assigned to this variable and will be used to filter the previous step which result is carried over in the current step. By not doing this you are simply telling Power Query to return true for all rows.