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:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD]11[/TD]
[TD]12[/TD]
[TD]Grand Total[/TD]
[/TR]
[TR]
[TD]2019[/TD]
[TD]10.33[/TD]
[TD]35.54[/TD]
[TD]15.24[/TD]
[TD]89.13[/TD]
[TD]50.50[/TD]
[TD]99.81[/TD]
[TD]108.73[/TD]
[TD]9.78[/TD]
[TD]11,441[/TD]
[/TR]
</tbody>[/TABLE]


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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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