Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello All,
I have a requirement to generate missing values based on the existing values.
I've used Peek Function to generate the values but i don't see the correct values in the generated value list.
Data:
PID | F2 Date | C Link ID | Life Time | Status |
1 | 10.09.2019 | 3 | 18.09.2019 | 5500 |
2 | 19.09.2019 | |||
2 | 19.09.2019 | 2 | 20.09.2019 | 6000 |
3 | 22.09.2019 | 8 | 24.09.2019 | 8000 |
3 | 25.09.2019 |
Expected Result:
PID | F2 Date | C Link ID | Life Time | Status |
1 | 10.09.2019 | 3 | 18.09.2019 | 5500 |
2 | 19.09.2019 | |||
2 | 19.09.2019 | 2 | 20.09.2019 | 6000 |
3 | 22.09.2019 | 8 | 24.09.2019 | 8000 |
3 | 22.09.2019 | 8 | 25.09.2019 | 8000 |
Result i Get after using Peek:
PID | F2 Date | C Link ID | Life Time | Status |
1 | 10.09.2019 | 3 | 18.09.2019 | 5500 |
2 | 10.09.2019 | 3 | 19.09.2019 | 5500 |
2 | 19.09.2019 | 2 | 20.09.2019 | 6000 |
3 | 22.09.2019 | 8 | 24.09.2019 | 8000 |
3 | 22.09.2019 | 8 | 25.09.2019 | 8000 |
The underlined part in the above table is completely wrong as PID = 2 has C Link ID=2 and F2 Date as 19.09.2019.
But because of Peek function i see that the values from PID=1 are filled for missing data in PID=2
PFA, sample app and also data.
Thanks!
You need to create a conditional verifying the current PID and the last PID, for example:
If ( PID = Peek ( PID ), Peek ( [F2 Date] ) ) as YourNewField
Resident YourTable
Order By PID asc;
Try this
Peek_Tmp:
LOAD
PID,
"F2 Date",
Status,
"C Link ID",
"Life Time"
FROM [lib://D/Peek.xlsx]
(ooxml, embedded labels, table is Sheet1);
NoConcatenate
Peek:
LOAD
PID,
"Life Time",
If(PID = Previous(PID), If(IsNull([F2 Date]), Peek([F2 Date]), [F2 Date]), [F2 Date]) AS [F2 Date],
If(PID = Previous(PID), If(IsNull([Status]), Peek([Status]), [Status]), [Status]) AS [Status],
If(PID = Previous(PID), If(IsNull([C Link ID]), Peek([C Link ID]), [C Link ID]), [C Link ID]) AS [C Link ID]
Resident Peek_Tmp
Order By PID;
Drop Table Peek_Tmp;
Any expert has a quick suggestion
You need to create a conditional verifying the current PID and the last PID, for example:
If ( PID = Peek ( PID ), Peek ( [F2 Date] ) ) as YourNewField
Resident YourTable
Order By PID asc;
Try this
Peek_Tmp:
LOAD
PID,
"F2 Date",
Status,
"C Link ID",
"Life Time"
FROM [lib://D/Peek.xlsx]
(ooxml, embedded labels, table is Sheet1);
NoConcatenate
Peek:
LOAD
PID,
"Life Time",
If(PID = Previous(PID), If(IsNull([F2 Date]), Peek([F2 Date]), [F2 Date]), [F2 Date]) AS [F2 Date],
If(PID = Previous(PID), If(IsNull([Status]), Peek([Status]), [Status]), [Status]) AS [Status],
If(PID = Previous(PID), If(IsNull([C Link ID]), Peek([C Link ID]), [C Link ID]), [C Link ID]) AS [C Link ID]
Resident Peek_Tmp
Order By PID;
Drop Table Peek_Tmp;
Thank you both. Works perfectly!