Forum Discussion
Fix DAX for Calculate cross tables
- 10 months ago
Hi All,
This has been resolved. It was just some data type issues and syntax errors on Table/Column Names.
This DAX is working fine.
Hi lovishsood1 ,
Thanks for the update. I’ve reviewed the logic and here is the version of the new table DAX. This version uses a CROSSJOIN between Employees and DateTable, and then adds the daily values from each activity table. It now returns the expected results for each employee and date.
Base_Output =
VAR BaseTable =
SUMMARIZE(
CROSSJOIN( Employees, DateTable ),
Employees[EmployeeCode],
Employees[FullName],
DateTable[FormatDate],
DateTable[Day Name]
)
RETURN
ADDCOLUMNS(
BaseTable,
"In Time", CALCULATE( MIN( PunchInRecords[In_Time] ) ),
"Out Time", CALCULATE( MAX( PunchOutRecords[Out_Time] ) ),
"Punch Hours",
COALESCE(
CALCULATE( SUM( TimeRecords[TotalHours] ) ),
DIVIDE(
DATEDIFF(
CALCULATE( MIN( PunchInRecords[In_Time] ) ),
CALCULATE( MAX( PunchOutRecords[Out_Time] ) ),
MINUTE
),
60
)
),
"Break Hours", CALCULATE( SUM( BreakRecords[BreakHours] ) ),
"Leave Count",
CALCULATE(
COUNTROWS(
FILTER(
'Leaves',
'Leaves'[EmployeeCode] = SELECTEDVALUE( Employees[EmployeeCode] )
&& 'Leaves'[FormatDate] = SELECTEDVALUE( DateTable[FormatDate] )
)
)
),
"Total Hours", CALCULATE( SUM( TimeRecords[TotalHours] ) )
)
Let me know if you want any help further.