Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Hakim-A
Creator
Creator

Exchange rate per date : filling missing data + fill in dates

Hello everyone,

 

My question today is this one :

I have a table representing currencies per date BUT the file is not completely filled in.

For example all Saturdays and Sundays and bank holidays my currencies are 0 and it's only filled in until the last Friday of the week before.

My file looks like this

 

Date_currencyCurrencyValue
01/01/2015USD-
02/01/2015USD1.2043
03/01/2015USD-
04/01/2015USD-
18/10/2019USD1.1144

 

What I would like to do is to fill in missing currency value with the value of the day before (for example on Saturday we put Friday value, on Sunday we put Saturday value which is also Friday value)

My data starts on 01/01/2015 and unfortunately all currencies value are 0 on this day in my file but I need to put the first value that is read for this currency.

You will see as an example for USD 01/01/2015 Value is empty but 02/01/2015 Value = 1.2043

I need to change 01/01/2015 Value to 1.2043

The same way : 03/01/2015 is saturday my value is 0 I need to put the value from the day before

Same thing for Sunday

And same thing for all weeks all currencies..

 

As you will see the data stops on Friday 18/10/2019, I would also need to generate 19 20 21 (today) dates for all currencies with the value of last Friday.

 

Quite complex right ?

 

Please have a look at my file and you will directly understand the issue I'm facing.

 

Thanks a lot for your contributions.

 

 

 

Labels (3)
1 Solution

Accepted Solutions
sunny_talwar

Try this

Table:
LOAD Date(Date#(Date_currency, 'DD/MM/YYYY')) as Date_currency,
	 currency,
     Num(Value, '#,##0.00', '.', ',') as Value
FROM
[..\..\Downloads\currencies.xlsx]
(ooxml, embedded labels, table is Sheet1);

tmpTable:
LOAD currency,
	 FirstSortedValue(Value, Date_currency) as Starting_value
Resident Table
Where Len(Trim(Value)) > 0
Group By currency;

Left Join (tmpTable)
LOAD Date(Min + IterNo() - 1) as Date_currency
While Min + IterNo() - 1 <= Today();
LOAD Min(Date_currency) as Min,
	 Max(Date_currency) as Max
Resident Table;

Left Join (tmpTable)
LOAD *
Resident Table;

DROP Table Table;

FinalTable:
LOAD currency,
	 Date_currency,
	 If(currency <> Previous(currency),
	 	If(Len(Trim(Value)) = 0, Starting_value, Value),
	 	If(Len(Trim(Value)) = 0, Peek('Value'), Value)
	 ) as Value
Resident tmpTable
Order By currency, Date_currency;

DROP Table tmpTable;

View solution in original post

2 Replies
sunny_talwar

Try this

Table:
LOAD Date(Date#(Date_currency, 'DD/MM/YYYY')) as Date_currency,
	 currency,
     Num(Value, '#,##0.00', '.', ',') as Value
FROM
[..\..\Downloads\currencies.xlsx]
(ooxml, embedded labels, table is Sheet1);

tmpTable:
LOAD currency,
	 FirstSortedValue(Value, Date_currency) as Starting_value
Resident Table
Where Len(Trim(Value)) > 0
Group By currency;

Left Join (tmpTable)
LOAD Date(Min + IterNo() - 1) as Date_currency
While Min + IterNo() - 1 <= Today();
LOAD Min(Date_currency) as Min,
	 Max(Date_currency) as Max
Resident Table;

Left Join (tmpTable)
LOAD *
Resident Table;

DROP Table Table;

FinalTable:
LOAD currency,
	 Date_currency,
	 If(currency <> Previous(currency),
	 	If(Len(Trim(Value)) = 0, Starting_value, Value),
	 	If(Len(Trim(Value)) = 0, Peek('Value'), Value)
	 ) as Value
Resident tmpTable
Order By currency, Date_currency;

DROP Table tmpTable;
Hakim-A
Creator
Creator
Author

Thanks for your reactivity - Your solution is working perfectly