DAX: Grand total correct, calculated fields incorrect

jocko327

New Member
Joined
Aug 1, 2019
Messages
1
The goal: In excel, determine hour by hour how much I am paying in labor versus how much we make in sales during that hour.

Tables:
Timesheets: Simple employee name, start time, stop time, date
Timesheets EDIT (separate table): unpivoted start and stop time. Now I have a column called shift, which indicates if it is shift start or end, the associated time, and an index so I know which start and end belong together.
Calendar: Excel date table
TimeTable: has every minute of a whole day and the hour that I want it to correspond to. e.g. 1:13 PM has a 13 in the Hour column.

This is the DAX that I am using right now:

Code:
SumHours:=sumx('Timesheets Edit',round(RELATED('Pay Rates'[Rate])*countrows(filter(TimeTable,if('Timesheets Edit'[Shift]="Start",TimeTable[Time]>'Timesheets Edit'[Time] && TimeTable[Time]<=LOOKUPVALUE('Timesheets Edit'[Time],'Timesheets Edit'[Shift],"End",'Timesheets Edit'[Index],'Timesheets Edit'[Index]),0)))/60,2))

This is what it yields:

56789101112Grand Total
201910.3335.5415.2489.1350.5099.81108.739.7811,441

<tbody>
</tbody>


I am basically trying to count the rows in the timetable that fall between start and end. The two tables are related by the time column, but the calculated fields are only showing the values summed for the hour in which the shift started. If somebody started a shift at 3:15AM, the value under the column '3' would read 45. If another person started at 3:45 am, that sum still works, and will show 60 minutes total. What it WON'T catch, is the full 60 minutes if somebody starts at 2:45 am and ends at 4:15 am. The grand total is correct, but I really need to be able to slice and dice this result.

Any suggestions?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top