Forum Discussion

Kelz's avatar
Kelz
Icon for Advocate I rankAdvocate I
4 years ago

Help: Traffic Light Staff Capacity formula

Hi,

 

I am trying to re-create a formula from one Power Bi report (built with Excel spreadsheets) into a new Power Bi (bulit with API's into the data) to show conditonal formatting in colour on a column chart and its not working.

 

Orignially, when recreating the formula it had an error that one of my cells was text but, now my data is all numbers and its still not showing the way I want. 

 

The data I want to show is a traffic light on the amount of hours a staff member has done in the month vs their individual capacity. ie Bob is expected to do 37.5 hours per week, the month of July 2021 has 4.29 weeks in the month, Bobs expected hours for July is 160.87 hours, Bob has actually worked 180 hours, which is 19.13 over his expected and needs to be shown as red.

 

The formulas used are

 

Weeks in Month = DATEDIFF(Dates[SOM], Dates[EOM], DAY) / 7

 

Capacity = SUMX('Harvest Employee', 'Harvest Employee'[Capacity] * SUMX(FILTER(Dates, Dates[Date] = Dates[SOM]), Dates[Weeks in Month]))
 
Free Time = [Capacity] - SUM('All data'[Hours])

 

the orignal graph appears as:

 

 

I have the same formulas in my new model, but the graph appears as: 

 

 

My data colour formmatting is:

 

My new model has the formulas:

 

Weeks in the month = Dates[Days in Month]/7
 
Monthly Capacity = sumx('Harvest - Users' , 'Harvest - Users'[weekly_capacity] * sumx(filter(Dates, Dates[Date] = Dates[SOM]), Dates[Weeks in the month]))

 

Free Time = [Monthly Capacity] - SUM('Project Data'[Hours])
 
My data has :
 
Table: Users - Employee & expected hours per week
Table: Timesheet - Employee & hours worked  (muilptle lines with different descriptions/hours for each project/task.
Table: Date's
 
Can somebody shed any light on why my formula is not working and/or how I fix it. 
 
Thanks
 
Kelz
 

 

13 Replies

  • v-robertq-msft's avatar
    v-robertq-msft
    Icon for Community Support rankCommunity Support

    Hi, Kelz 

    According to your description and sample pictures, I can roughly understand your requirement, I think you can try to create a measure to define the data color manually instead set it in the color formatting, you can try this measure:

    Color =
    
    SWITCH(
    
        TRUE(),
    
        [Free Time]<-10,"Red",
    
        [Free Time]>=-9&&[Free Time]<1,"Yellow",
    
        [Free Time]>1&&[Free Time]<=1000,"Green")

    Then go to the data color setting of this column chart, set like this:

     

    And you can get what you want, like this:

     

    You can download my test pbix file below

    Thank you very much!

     

    Best Regards,

    Community Support Team _Robert Qin

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Kelz's avatar
      Kelz
      Icon for Advocate I rankAdvocate I

      Hi, 

       

      Thanks for that, it didnt work, but i think it might be because I need to link it to the indivdual/unique staff members. 

       

      ie bob is 37.5, sally is 20 hours, jane is 30 hours which is under the employee tab. 

       

      do you know how I can get the free time formula to filter on each of the staff members capacity and not the whole group? 

       

      thanks 

       

      kelz

      PREVIEW
       
       
       
      • v-robertq-msft's avatar
        v-robertq-msft
        Icon for Community Support rankCommunity Support

        Hi, 

        According to your description, I can roughly understand what you want to get. But I find it hard to create the test data based on your requirement details. Would you like to post some sample data in table form or pbix file(without sensitive data) and your expected result(like the chart you want to get and the correct measure value based on your sample data)?

        Thanks very much!

        How to Get Your Question Answered Quickly 

         

        Best Regards,

        Community Support Team _Robert Qin

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-robertq-msft's avatar
    v-robertq-msft
    Icon for Community Support rankCommunity Support

    Hi, 

    According to your description and sample picture, I think you can try to use these measures to create a column chart to achieve your requirement:

    Free Time =
    
    var _sum=CALCULATE(SUM('Timesheet data'[hours]),FILTER(ALL('Timesheet data'),[Employee]=MAX('staff table'[Employee])))
    
    return
    
    SUM([Capacity])-_sum
    Color =
    
    SWITCH(
    
        TRUE(),
    
        [Free Time]<-10,"Red",
    
        [Free Time]>=-9&&[Free Time]<1,"Yellow",
    
        [Free Time]>1&&[Free Time]<=1000,"Green")

    And you can create a column chart to set the data color like this to get what you want:

     

    You can download my test pbix file below

    Thank you very much!

     

    Best Regards,

    Community Support Team _Robert Qin

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Kelz's avatar
      Kelz
      Icon for Advocate I rankAdvocate I

      Hi Robert, 

       

      Sorry to be a pain, that didnt quite work. 

       

      I need to show the hours the employees completed each month, but coloured coded depending on whether they met or exceeded their hours in the coloumn graph:

       

      ie

      Bob worked 185 hours in October (Sum of timesheet hours - timesheet table)

      Bob's capacity per week is 40 hours (capactity - employee table)

      in the month of October there are 4.29 weeks (weeks in the month - Dates table)

      Bob's expected hours is 4.29 x 40 = 171.60 for the month of October. (capacity x weeks in month)

       

      Free time  = Expected hours - actual hours 

      in bob's case - 171.60 - 185 = -13.4

      If free time is greater than -10 = red (ie they did too much)

      If free time is between 2 & -9 = Green (they worked their hours/ slight over)

      If the free time is less than 2 = Yellow  (they havent done all thier hours)

       

      in the coloumn graph, bob's hours would show red. 

       

      Thanks

       

      Kelz

  • v-robertq-msft's avatar
    v-robertq-msft
    Icon for Community Support rankCommunity Support

    Hi, 

    According to your description, I think you can make some changes on the measure [Free time] to get the requirement you wanted:

    Free Time =
    
    var _date=EOMONTH(TODAY(),-1)
    
    var _weeks=divide(DATEDIFF(DATE(YEAR(_date),MONTH(_date),1),EOMONTH(_date,0),day),7)
    
    var _sum=CALCULATE(SUM('Timesheet data'[hours]),FILTER(ALL('Timesheet data'),[Employee]=MAX('Timesheet data'[Employee])))
    
    return
    
    MAX('staff table'[Capacity])*_weeks-_sum

    You can define the first variable _date according to your needs, in this case, is the last date in October

    Then you can do the same thing as my above replies to achieve your needs:

    Color =
    
    SWITCH(
    
        TRUE(),
    
        [Free Time]<-10,"Red",
    
        [Free Time]>=-9&&[Free Time]<1,"Yellow",
    
        [Free Time]>1&&[Free Time]<=1000,"Green")

     

    Thank you very much!

     

    Best Regards,

    Community Support Team _Robert Qin

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Kelz's avatar
      Kelz
      Icon for Advocate I rankAdvocate I

      Hi Robert, 

       

      sorry it didnt work. I dont want to show the "Free Time". I want to show the amount of hours that the staff member has done, and I want the color to be based on whether they have done their hours or not. I

      also have a splicer on the dates, so I want it to change based on whatever month is choosen

       

       

       

      Cheers

       

      Kelz

       

       

      • KNP's avatar
        KNP
        Icon for Super User rankSuper User

        Hi Kelz - Did you mark this as solved? I see it is marked as solved but your latest question came in after the "solution".

         

  • Kelz , I think 1st and 3rd condition has a problem. Reconsider and correct. Alos you should number at all place, you are using percent in first one

    • Kelz's avatar
      Kelz
      Icon for Advocate I rankAdvocate I

      Hi amitchandak 

       

      Thanks for the suggestion, I tried it, but when changing it to a number it comes up as a red box 

       

      and that color formatting works in my old model 

       

      Cheers, 

       

      Kelz