Forum Discussion

GTRailey's avatar
GTRailey
Frequent Visitor
9 years ago
Solved

Standard Deviation and Z-Score calculation depending on time slicer

I am looking to calculate the z-scores for the number of calls answered by a given call center agent.  Each Agent can have either a standard or non-standard role.   I have an Agent_Data table cont...
  • GTRailey's avatar
    GTRailey
    9 years ago

    I fixed the problem.  In case anyone out there is curious, here is how I did it.

     

    PBIX - https://1drv.ms/u/s!Ar0HG-aZJh_ZhTPiiyKo0VDhPdLa

     

    I started with two queries, Agent_Data, and Call_Data.  Agent_Data has three columns:
    Name - The Agent's full name
    id - The Agent's unique id
    Role - Standard or Nonstandard

     

    Call_Data has two Columns:

    Agent - The Agent's full name
    StartTime - The date and time of the inbound call

     

    Using PowerQuery:

    1. I created a new Date column in Call_Data that extracts the date from StartTime using Date.From()

    2. I made a copy of Agent_Data by right-clicking>Duplicate.  I called this table "Totals."
    3. I removed all columns from "Totals" except for the id column.

    4. I added a custom Date column to "Totals" using the List.Dates() function.  I called this "Date."

    5. I expanded the "Date" column and changed the type to Date.

     

    This gave me a table with each agent name listed once for every date in the range.

     

    Using Dax:

    1. I created a table called "Calendar" by using the Calendar() function.  I created the following relationships:

    a. Agent_Data[Name] <> Call_Data[Agent]

    b. Agent_Data[id] > Totals[id]

    c. Calendar[Date] > Call_Data[StartDate]

    d. Calendar[Date] > Totals[Date]

    2. I created a Measure M_Calls_Taken = COUNTA(Call_Data[StartDate])+0

    3. I created a column 'Totals'[Calls_Taken] = M_Calls_Taken

    4. I created the following additional Measures:

    COUNT_Calls_Taken = calculate(DISTINCTCOUNT('Totals'[id]),allselected('Totals'))
    SUM_Calls_Taken = calculate(sum('Totals'[Calls_Taken]),allselected('Totals'))+0

    Mean_Calls_Taken = [SUM_Calls_Taken]/[COUNT_Calls_Taken]

    Var_squaredif = Power(sum('Totals'[Calls_Taken])-[Mean_Calls_Taken],2)

    Var_Calls_Taken = var difsquare = SUMX(ALLSELECTED(Agent_Data),[Var_squaredif]) return difsquare/[COUNT_Calls_Taken]

    StDev_Calls_Taken = sqrt([Var_Calls_Taken])

    Z-Score_Calls_Taken = ([M_Calls_Taken]-[Mean_Calls_Taken])/[StDev_Calls_Taken]

     

    This allowed me to select various dates within my range along with different roles at the report level and adjust the Z-Scores on the fly.  I posted this reply immediately after fixing the issue, so there is still a bit of cleanup/consolidating to do, but hopefully the above steps will help with thinking through any similar issues.

     

    Thank you.