Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello
I have two tables:
employee timesheet with employee, role, date , date year, date month and hours worked on that date
standard hours - date and standard hours for that date
I want to show both figures in a pivot table pivoted by role, employee, year, month - whith each cell showing me the amount of hours the employee worked that month and the number of standard hours for that month (basically the standard hours figure is the same for all employees)
I have Sum(HoursWorked) to show the hours worked, and SUM(StandardHours) to show the standard hours
So far so good
The problem begings on those months where a certain employee had no records at all. For some reason, for those months the standard hours figure is showing zero as well, even though it should show the figure from the standard hours table, which exists
What am I doing wrong, or what should I change to make it work?
I did something to identify hours worked by month to identify employees that did not input hours total or partially in the script
mindate:
load
min(num(Fecha)) asfechamin
resident
MSP_TimesheetActual;
replace
LET varMinDate = Num(Peek('fechamin', 0, 'mindate'));LET
varMaxDate = floor( Num(monthend(Today()),0));//LET varMaxDate = Num(Today());
//Create all fullmpnths in the range from varMinDate to varMaxDate, this is to incude accumulations in months without enrollments
TempCal:
LOAD
$(varMinDate)
+Iterno()-1 AS Num,
Date
($(varMinDate)+Iterno()-1) ASTempDate
AUTOGENERATE
1 WHILE $(varMinDate)+Iterno()-1<= $(varMaxDate);
//Building the master calendar with most date dimensions
table_aux:
load
distinct date(TempDate, 'YYYY-MM-DD') asFechavinc_AUX
resident
TempCal order by TempDateAsc;
Drop
tableTempCal;
// take all periodo and all AUDAFFILIATIONNUMBER
join
load
distinctrecurso1
asrecurso_AUX
resident
MSP_TimesheetResource
//order by keyusermonth,Fecha
where
not exists(R1, recurso1);
auxtable
:
load
Fechavinc_AUX
AS creationdate,
recurso_AUX
ASrecurso
resident
table_auxorder
by recurso_AUX ,Fechavinc_AUX;
left
join
load
recurso
,
creationdate
,
sum
(Horas) ascantidad
resident
timesheet1where
flagappr=1group
by recurso , creationdateorder
by recurso , creationdate;
//store auxtable into auxtable.qvd;
//drop table table_aux;
horasporusermes:
load
distinct
recurso
,
left
(creationdate,10) as Fecha,
if
(isnull(cantidad) or cantidad<1,0,cantidad) AS Cantidademp,
//numsum (if ( AUDAFFILIATIONNUMBER = PEEK(AUDAFFILIATIONNUMBER) , rangesum ( cantidad , peek (acumactiv1)) , cantidad)) as acumactiv1
rangesum (if ( recurso = previous(recurso) and monthname(creationdate)=previous(monthname(creationdate)) , rangesum ( cantidad , peek (acumactiv1)) , cantidad)) asacumactiv1
resident
auxtableorder
by recurso , creationdate;
drop
tableauxtable;
drop
tabletable_aux;