Forum Discussion

anupampandey's avatar
anupampandey
Icon for Helper III rankHelper III
9 years ago
Solved

Average (per month per sales representative)

Hi,

 

I am having a situation where I am not getting the desired result for average value. I have to calculate the monthly average commission per sales representative based on it benchmarking will be done. I am using below statement:

 

AVG = CALCULATE(AVERAGE('Table'[Total Commission]),FILTER(all(Calender),Calender[DateKey]<=MAX(Calender[DateKey])))

 

Below is the result I am getting while pivoting the data in excel but unable to get the same in pbi.Sample

 

 

 

 

 

 

 

 

 

Columns 1 to 12 are months.

Please let me know where I am making mistake.

 

Thanks,

Anupam

  • richbenmintz's avatar
    richbenmintz
    9 years ago

    Hi anupampandey,

     

    I have come up with a solution for you to visualize your data in Chart using a disconneted dimension and a contextually sensative measure.

    Method

    1. Click 'Enter Data' and add your Bins as rows along with an Order by value

    2. Create a measure that reactes to the value of the 'Bin' on Rows Columns or Filters (if you do not do this the value for each bin will always be the same)

     

    Bin Count = 
    var bintable = SUMMARIZE('CommissionYTD', 'CommissionYTD'[RETMST_ID], "avg", [Avg. Commission])
    var bin = COUNTROWS(bintable)
    return 
    if(HASONEVALUE('Groups'[Bins]), 
    SWITCH(values('Groups'[Bins]), 
    "A,B", CALCULATE(COUNTX(filter(bintable, [avg] > 1500), bin)),
    "C", CALCULATE(COUNTX(filter(bintable, [avg] >= 1000 && [avg] < 1500), bin)),
    "D", CALCULATE(COUNTX(filter(bintable, [avg] >= 750 && [avg] < 1000), bin)),
    "E", CALCULATE(COUNTX(filter(bintable, [avg] > 0 && [avg] < 750), bin))
    , blank()))

    The Measure does the following:

    - creates a variable to store the avg commision for Rep

    - creates a variable to store the count of rows in the variable table

    - Uses an if condition to ensure that the 'Group'[Bins] column only contains a single value, this gaurds against using the values function on a column containing multiple values

    - Uses the Switch construct to test for the value in the 'Group'[Bins] column, for each valid result a calculate formula returns the count of rows from the bintable where the [avg] value in the bintable meets the requirement (note that countx is used as we need to iterate over the rows in the table to get the correct value.

     

    you can find the working solution here

     

    link to pbix

  • anupampandey's avatar
    anupampandey
    9 years ago

    Hi richbenmintz,

     

    Thanks for help. I implemented in my main data model.

     

    Again thanks a lot :smileyhappy:

     

    Regards,

    Anupam


    richbenmintz wrote:

    Hi anupampandey,

     

    I have come up with a solution for you to visualize your data in Chart using a disconneted dimension and a contextually sensative measure.

    Method

    1. Click 'Enter Data' and add your Bins as rows along with an Order by value

    2. Create a measure that reactes to the value of the 'Bin' on Rows Columns or Filters (if you do not do this the value for each bin will always be the same)

     

    Bin Count = 
    var bintable = SUMMARIZE('CommissionYTD', 'CommissionYTD'[RETMST_ID], "avg", [Avg. Commission])
    var bin = COUNTROWS(bintable)
    return 
    if(HASONEVALUE('Groups'[Bins]), 
    SWITCH(values('Groups'[Bins]), 
    "A,B", CALCULATE(COUNTX(filter(bintable, [avg] > 1500), bin)),
    "C", CALCULATE(COUNTX(filter(bintable, [avg] >= 1000 && [avg] < 1500), bin)),
    "D", CALCULATE(COUNTX(filter(bintable, [avg] >= 750 && [avg] < 1000), bin)),
    "E", CALCULATE(COUNTX(filter(bintable, [avg] > 0 && [avg] < 750), bin))
    , blank()))

    The Measure does the following:

    - creates a variable to store the avg commision for Rep

    - creates a variable to store the count of rows in the variable table

    - Uses an if condition to ensure that the 'Group'[Bins] column only contains a single value, this gaurds against using the values function on a column containing multiple values

    - Uses the Switch construct to test for the value in the 'Group'[Bins] column, for each valid result a calculate formula returns the count of rows from the bintable where the [avg] value in the bintable meets the requirement (note that countx is used as we need to iterate over the rows in the table to get the correct value.

     

    you can find the working solution here

     

    link to pbix



    richbenmintz wrote:

    Hi anupampandey,

     

    I have come up with a solution for you to visualize your data in Chart using a disconneted dimension and a contextually sensative measure.

    Method

    1. Click 'Enter Data' and add your Bins as rows along with an Order by value

    2. Create a measure that reactes to the value of the 'Bin' on Rows Columns or Filters (if you do not do this the value for each bin will always be the same)

     

    Bin Count = 
    var bintable = SUMMARIZE('CommissionYTD', 'CommissionYTD'[RETMST_ID], "avg", [Avg. Commission])
    var bin = COUNTROWS(bintable)
    return 
    if(HASONEVALUE('Groups'[Bins]), 
    SWITCH(values('Groups'[Bins]), 
    "A,B", CALCULATE(COUNTX(filter(bintable, [avg] > 1500), bin)),
    "C", CALCULATE(COUNTX(filter(bintable, [avg] >= 1000 && [avg] < 1500), bin)),
    "D", CALCULATE(COUNTX(filter(bintable, [avg] >= 750 && [avg] < 1000), bin)),
    "E", CALCULATE(COUNTX(filter(bintable, [avg] > 0 && [avg] < 750), bin))
    , blank()))

    The Measure does the following:

    - creates a variable to store the avg commision for Rep

    - creates a variable to store the count of rows in the variable table

    - Uses an if condition to ensure that the 'Group'[Bins] column only contains a single value, this gaurds against using the values function on a column containing multiple values

    - Uses the Switch construct to test for the value in the 'Group'[Bins] column, for each valid result a calculate formula returns the count of rows from the bintable where the [avg] value in the bintable meets the requirement (note that countx is used as we need to iterate over the rows in the table to get the correct value.

     

    you can find the working solution here

     

    link to pbix


     

17 Replies

  • richbenmintz's avatar
    richbenmintz
    Icon for Resident Rockstar rankResident Rockstar

    It looks like  for every month you will get the LTD average value, you are clearing the filter context from the calendar table and then filtering it to include all members <= the end of the month value, assuming you are using months on your columns. One thing to note as well is that if you have not filtered your table by a year then the 1-12 value will repeat for every year and the max value will be the max for each of the month slices.

     

    Hope that makes sense

    • anupampandey's avatar
      anupampandey
      Icon for Helper III rankHelper III

      Hi richbenmintz,

       

      Could you alter my calculation statement please that would be of great help?

       

      Thanks,

      Anupam

      • richbenmintz's avatar
        richbenmintz
        Icon for Resident Rockstar rankResident Rockstar

        If you can send me the pbix file then I will try to provide you with a formula that will work for you. As a side note, have you tried the new quick measures function in power bi desktop for this measure?