Forum Discussion

DaxNewbie's avatar
DaxNewbie
Frequent Visitor
8 years ago
Solved

Dynamic filtering basing on slicer selection

Hello, 

 

I have a dataset including names, titles, tasks, and time worked (see below). I would like to calculate the avg. time worked by task per employee, but also the average time worked by task by the group (indicated by the title) to which that employee belongs. So if an employee is select and she is a partner, the the group average per task would be for only the partners. 

 

Data:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Avg Per Employee:

 

 

 

 

 

 

 

Avg Per Title: 

 

I understand why 'AvgTime' matches 'AvgTimebyTitle'. I just do not know how to instruct Power BI to find the average for all employees whose title is also 'Partner' (the same title as Amy). 

 

 

 

 

 

 

 

 

Currently I am using this code: 

AvgTimebyTitle = CALCULATE(AVERAGE(Sheet1[Time]),Filter(Sheet1, Sheet1[Title] = SELECTEDVALUE(Sheet1[Title])))

 

 

Any assistance is most appreciated. 

 

Cheers!

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    I believe you will need to create a VAR that leverages CALCULATETABLE with an ALL('Data'[Title]). Once you have that, then you can do a GROUPBY with an AVERAGEX across that table to get the average you desire. Something like that. Can you post your data in a form that can be easily copied and pasted?

     

    Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    • DaxNewbie's avatar
      DaxNewbie
      Frequent Visitor

      Hi Greg_Deckler: Thank you so much for replying. I believe that I understand the methodology you explained in your post. 

      I am also included the data below in a more copy-friendly format. 

       

      Thank you!

       

      NameTitleTaskTime
      SamManagerResearch2
      SamManagerPitch3
      SamManagerDeal Closing4
      SamManagerAdmin8
      SamManagerResearch9
      SamManagerPitch2
      SamManagerDeal Closing1
      SamManagerAdmin6
      AmyPartnerResearch7
      AmyPartnerPitch8
      AmyPartnerDeal Closing8
      AmyPartnerAdmin8
      AmyPartnerResearch7
      AmyPartnerPitch7
      AmyPartnerDeal Closing6
      AmyPartnerAdmin6
      MichellePartnerResearch14
      MichellePartnerPitch15
      MichellePartnerDeal Closing13
      MichellePartnerAdmin12
      MichellePartnerResearch10
      MichellePartnerPitch11
      MichellePartnerDeal Closing12
      MichellePartnerAdmin13