Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
StudentID | Absence | FromDatetime | ToDatetime |
---|---|---|---|
1 | Sick | 01/01/2015 00:00:00 | 01/01/2015 23:59:59 |
1 | Sick | 04/01/2015 00:00:00 | 05/01/2015 23:59:59 |
1 | Exam | 07/01/2015 00:00:00 | 07/01/2015 23:59:59 |
2 | Exam | 07/01/2015 00:00:00 | 07/01/2015 23:59:59 |
LOAD
StudentID, Absence, FromDatetime, ToDatetime
FROM
$(vPath)\Diary.qvd
(qvd) ;
Hi, I have an issue where I'm trying to evaluate the above table to find instances where StudentID AND Absence are the same as the previously loaded line. When this occurs I need to generate a line of data for the same StudentID but with the following:
I'm assuming peek() should be used to evaluate StudentID and Absence which I'm fine with. However, I'm struggling to generate the additional line whenever the criteria is met. Any help would be greatly appreciated...
Example of required output would be:
StudentID | Absence | FromDatetime | ToDatetime |
---|---|---|---|
1 | Sick | 01/01/2015 00:00:00 | 01/01/2015 23:59:59 |
1 | Attending | 02/01/2015 00:00:00 | 02/01/2015 00:00:00 |
1 | Sick | 04/01/2015 00:00:00 | 05/01/2015 23:59:59 |
1 | Exam | 07/01/2015 00:00:00 | 07/01/2015 23:59:59 |
2 | Exam | 07/01/2015 00:00:00 | 07/01/2015 23:59:59 |
Try
Load
RowNo() as RowNo,
StudentID,
ShouldBeDuplicated,
If(IterNo()=1 and ShouldBeDuplicated,'Attending',Absence) as Absence,
If(IterNo()=1 and ShouldBeDuplicated,TimeStamp(Previous(ToDatetime)+1/24/60/60),FromDatetime) as FromDatetime,
If(IterNo()=1 and ShouldBeDuplicated,TimeStamp(Previous(ToDatetime)+1/24/60/60),ToDatetime) as ToDatetime
While IterNo() =1 or (IterNo()=2 and ShouldBeDuplicated);
Load *,
StudentID=Previous(StudentID) and Absence=Previous(Absence) as ShouldBeDuplicated
From … ;
HIC
Try
Load
RowNo() as RowNo,
StudentID,
ShouldBeDuplicated,
If(IterNo()=1 and ShouldBeDuplicated,'Attending',Absence) as Absence,
If(IterNo()=1 and ShouldBeDuplicated,TimeStamp(Previous(ToDatetime)+1/24/60/60),FromDatetime) as FromDatetime,
If(IterNo()=1 and ShouldBeDuplicated,TimeStamp(Previous(ToDatetime)+1/24/60/60),ToDatetime) as ToDatetime
While IterNo() =1 or (IterNo()=2 and ShouldBeDuplicated);
Load *,
StudentID=Previous(StudentID) and Absence=Previous(Absence) as ShouldBeDuplicated
From … ;
HIC
This does exactly what I needed. I removed the "+1/24/60/60" from the FromDatetime and ToDatetime fields and it is spot on. Thank you Henric, you saved me pulling my hair out!