How to populate date missing value and relative data
Sometimes when you load data into QlikView you find you are missing some value of field but these values are required to populate the chart. Also you need some dummy data(avg figure) for missing values.
It could be like in the table to the right where you have three dates, each with some kind of conversion rate. The table only contains the dates where the conversion rate changed, not the dates between the changes.
However, the user will want to ask the question: “What was the status on this specific day?” In other words, the user wants to be able to click on a reference date to see the number that is associated with this date – but the date might not exist in the source data.
In such a situation, you need to generate the missing dates between the changes as individual records and use the “Rate” value from the previous date.
There are several ways to do this in QlikView, and all of them involve some script programming, using temporary tables. One algorithm is
- Load the source table containing the rates (below called “Rates”).
- Find largest and smallest date in the “Rates” table.
- Generate all dates between the largest and smallest dates (below called “Dates”)..
- Join the “Dates” table (outer join) onto the “Rates” table.
- Sort the resulting table according to date.
- Propagate the value of “Rate” downwards to all records that have NULL in the “Rate” field, using the Peek() function.
Visually, the join and peek steps of the algorithm look like this:
In the QlikView script, the algorithm would look like the following:
TempTable_Rates: Load Date, Rate From Rates ;
MinMaxDate: Load Min(Date) as MinDate, Max(Date) as MaxDate resident TempTable_Rates; Let vMinDate = Peek('MinDate',-1,'MinMaxDate') - 1; Let vMaxDate = Peek('MaxDate',-1,'MinMaxDate') ;
Join (TempTable_Rates)
Load Date(recno()+$(vMinDate)) as Date Autogenerate vMaxDate - vMinDate;
Rates:
NoConcatenate Load Date,
If( IsNull( Rate ), Peek( Rate ), Rate ) as Rate Resident TempTable_Rates Order By Date ; /* so that above values can be propagated downwards */
If( IsNull( Rate ), Peek( Rate ), Rate ) as Rate Resident TempTable_Rates Order By Date ; /* so that above values can be propagated downwards */
Drop Table MinMaxDate, TempTable_Rates;
As we know there are many companies which are converting into Big data implementation services with the right direction we can definitely predict the future.
ReplyDeleteI feel there is a need to find out about more and more tools which ease out complex database and problem solving aspects.There is actually a need to make use of embedded tools with this.
ReplyDeleteQlik Rest Api Connection