Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate Staff cost per hour of the day

Hello

 

I'm trying to calulate the cost per hour for staff to compare to revenue.

I have the timesheet data that shows when they started and finished, along with the costs.  i have created a second table that breaks this out into start of hour rows. Example below

 

GordyMac_0-1679325018420.png

 

What i can't work out how to do is calculate is the cost per hour. So for example I have 2 staff working 16:00 to 17:00 and one 16:00 to 16:30

all on £10 per hour.

cost for this hour should be £25

 

how to i add the cost for the hour starting at 16:00?

 

Thanks

 

2 ACCEPTED SOLUTIONS

@Anonymous I *think* this might be it. See PBIX attached below signature.

Hours = 
    ADDCOLUMNS(
        GENERATE( 
            SELECTCOLUMNS(
                GENERATESERIES(0, 23,1),
                "Hour", [Value]
            ),   
            SELECTCOLUMNS(
                GENERATESERIES(0, 59, 1),
                "Minute",[Value]
            )
        ),
        "HourMinute", [Hour]/24 + [Minute]/24/60
    )

 

Measure = 
    VAR __Hour = MAX('Hours'[Hour])
    VAR __Table =
        SELECTCOLUMNS(
            ADDCOLUMNS(
                FILTER(
                    GENERATE(
                        'Table',
                        'Hours'
                    ),
                    [HourMinute] >= [StartTime] && [HourMinute] <= [EndTime]
                ),
                "Cost Per Minute", DIVIDE( [Cost], [Mins] )
            ),
            "Index",[Index],
            "Hour",[Hour],
            "HourMinute",[HourMinute],
            "CostPerMinute",[Cost Per Minute]
        )
    VAR __Result = SUMX(FILTER(__Table, [Hour] = __Hour),[CostPerMinute])
RETURN
    __Result

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

@Anonymous First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

@Greg_Deckler thats amazing, thank you so much for doing this!

i have added into my model and it works, thank you.  i have a further question, how can i get it to sum the total for the day?

 

GordyMac_0-1679392676298.png

so for example in my model i have sessions where i can total the sales/revenue and i want to then compare the cost per hour.

GordyMac_1-1679392808020.png

This is all new to me so your help so far has been invaluable.

 

 

@Anonymous First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  I have done something similar to GordyMac, with the service periods, but am struggling to get the group totals to work.

 

Firstly I created a column on the hours table using the below

Service Period = SWITCH (
      TRUE (),
      Hours[Hour] >= 6.00 && Hours[Hour] <= 11.29 , "Breakfast",
     Hours[Hour] >= 11.30 && Hours[Hour] <= 15.59 , "Lunch",
     Hours[Hour] >= 16.00 && Hours[Hour] <= 21.59  , "Dinner",
     Hours[Hour] >= 22.00 || Hours[Hour] <= 2.59  , "Late Night",
     Hours[Hour] >= 3.00 && Hours[Hour] <= 5.59  , "Other"
)
 
I then used your measure/matrix fix to create a Period Cost
Period Cost =
VAR __table = SUMMARIZE('Hours',[Service Period],"__value",[Hourly Cost])
RETURN
IF(HASONEVALUE(Hours[Service Period]),[Hourly Cost],SUMX(__table,[__value]))
 
But this doesnt seem to summarise for the period, only for the total
Westy85_0-1685503571118.png

 

Sorry if this is covered in the links you have posted, I am still very much learning, and have probably missed something obvious.

 

any assistance is greatly appreciated!

 

Thanks

Anonymous
Not applicable

@Greg_Deckler Thanks again!  i was actually going through the Final Word solution before you posted it as i was searching this morning, so thanks for that post too!  You explain the solutions really well. 

Greg_Deckler
Super User
Super User

@Anonymous It's going to be a variation of this the below links (Open Tickets) but based on hour not day. If you can post sample data as text can probably mock it up.


Take a look at these two Quick Measures as I think you want something like them.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler 

Thanks for the quick response! 

I have added the data in the table below that is the source information, before the extra rows are added in power query. 

The examples you showed would be a perfect solution, thanks

 

StartingDateDeptIdEmpIdStartTimeEndTimeDurationPayIdMinsCostHolidayAccrual
03-Mar-2303-Mar-231251112:0017:0005:00230047.55.732758621
03-Mar-2303-Mar-231292816:0123:2207:21244169.8258.427155172
03-Mar-2303-Mar-231398217:0023:1506:15237546.8755.657327586
03-Mar-2303-Mar-231398716:0019:1603:16219620.31866672.452252874
03-Mar-2303-Mar-231398719:4421:0001:162767.878666670.950873563
03-Mar-2303-Mar-231427417:5918:5800:592597.3750.890086207
03-Mar-2303-Mar-23111010:0013:0503:05218529.29166673.535201149
03-Mar-2303-Mar-23111013:3216:0002:28214823.43333332.82816092
03-Mar-2303-Mar-231427016:0017:5801:58211814.751.780172414
03-Mar-2303-Mar-231427018:2623:1504:49228936.1254.359913793
03-Mar-2303-Mar-231206310:0016:0006:002360576.879310345
03-Mar-2303-Mar-231427118:0022:0004:00224036.724.431724138
03-Mar-2303-Mar-231437716:0023:2507:25244570.45833338.503591954
03-Mar-2303-Mar-23115813:0021:0008:002480829.896551724
03-Mar-2303-Mar-231244415:3323:3007:57247781.48759.834698276
03-Mar-2303-Mar-23111013:0513:3200:271274.2750.515948276
03-Mar-2303-Mar-231398719:1619:4400:281282.902666670.350321839
03-Mar-2303-Mar-231427017:5818:2600:281283.50.422413793

@Anonymous I *think* this might be it. See PBIX attached below signature.

Hours = 
    ADDCOLUMNS(
        GENERATE( 
            SELECTCOLUMNS(
                GENERATESERIES(0, 23,1),
                "Hour", [Value]
            ),   
            SELECTCOLUMNS(
                GENERATESERIES(0, 59, 1),
                "Minute",[Value]
            )
        ),
        "HourMinute", [Hour]/24 + [Minute]/24/60
    )

 

Measure = 
    VAR __Hour = MAX('Hours'[Hour])
    VAR __Table =
        SELECTCOLUMNS(
            ADDCOLUMNS(
                FILTER(
                    GENERATE(
                        'Table',
                        'Hours'
                    ),
                    [HourMinute] >= [StartTime] && [HourMinute] <= [EndTime]
                ),
                "Cost Per Minute", DIVIDE( [Cost], [Mins] )
            ),
            "Index",[Index],
            "Hour",[Hour],
            "HourMinute",[HourMinute],
            "CostPerMinute",[Cost Per Minute]
        )
    VAR __Result = SUMX(FILTER(__Table, [Hour] = __Hour),[CostPerMinute])
RETURN
    __Result

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.