DAX: Grand total correct, calculated fields incorrect


New Member
Aug 1, 2019
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.

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:

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


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?

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...