`
Current Dataset- Has dates, ID and Values
Date | ID | Value
--------------------
2/4/17 | 3 | 4.4
2/4/17 | 9 | 6.2
2/9/17 | 3 | 4.7
2/9/17 | 4 | 7.4
2/9/17 | 9 | 9.4
2/11/17 | 3 | 9.7
2/11/17 | 7 | 12.4
`Expected result - I want to populate missing dates and peek each ID and their value until the next Date.
Expected Result
Date | ID | Value
--------------------
2/4/17 | 3 | 4.4
2/4/17 | 9 | 6.2
2/5/17 | 3 | 4.4
2/5/17 | 9 | 6.2
2/6/17 | 3 | 4.4
2/6/17 | 9 | 6.2
2/7/17 | 3 | 4.4
2/7/17 | 9 | 6.2
2/8/17 | 3 | 4.4
2/8/17 | 9 | 6.2
2/9/17 | 3 | 4.7
2/9/17 | 4 | 7.4
2/9/17 | 9 | 9.4
2/10/17 | 3 | 4.7
2/10/17 | 4 | 7.4
2/10/17 | 9 | 9.4
2/11/17 | 3 | 9.7
2/11/17 | 7 | 12.4
When having such case I'm usually using something like the script below.
Basically im "filling" the missing dates but cross joining all possible dates will all possible
ID
values and then checking the previousValue
values.Be aware that cross joining will produce big tables - for example having 10
Dates
and 10ID
will result in table with 100 rows, 20Dates
and 20ID
- 400 rows etc and if we have too much history and too much IDs ... the things can go nasty quite quickly (keep an eye on the memory consumption)After running the script this will be the result:
You can download an example QV file here