Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Need Script help!

Hello everybody!

I need help to read in a Movex table through ODBC connection with exchange rates uppdated daily.

field1: Currency    (EUR,USD,CAD,CHY.....)

field2: Rate          (for each currency)

field3: Date

field4: Changenr   (if the rate changes more than ones a day this number increases, so it must be the max value)

How do i write the script so that only the diffrent currencies is displayed with the right rate from the last daterecord of each currency?

(i only want one row for each currency with the latest rate).

Please dont answer in a qvw file, because i cant open it.

Thanks/Patric

1 Solution

Accepted Solutions
anderslinden
Partner - Contributor III
Partner - Contributor III

Hi! This may not be the most beautiful solution but it seems to work. Note that my date format is not the same as yous so you might have to work with your date formatting to get the join to work properly.

OriginTable:

LOAD CUCUCD,
CUARAT,
CUCUDT,
CUCRTP
FROM
CurrencyTables.xlsx
(
ooxml, embedded labels, table is Blad1)
;
FinalTable:
LOAD CUCUCD,
max(CUCUDT) as MaxCUCUDT
resident OriginTable
group by CUCUCD ;

left join (FinalTable)
load CUCUCD,
CUCUDT as MaxCUCUDT,
max(CUCRTP) as MaxCUCRTP
resident OriginTable
group by CUCUCD,CUCUDT ;

left join (FinalTable)
load CUCUCD,
CUCUDT as MaxCUCUDT,
CUCRTP as MaxCUCRTP,
CUARAT as LastRate
resident OriginTable
;
drop table OriginTable;

Regards, Anders

BI Consultant, Business Information Providers
www.bipab.se

View solution in original post

4 Replies
vgutkovsky
Master II
Master II

You could do something like this:

data:

LOAD

     Currency,

     Rate,

     Date,

     Changenr

SELECT ...

FROM ...

;

LEFT JOIN (data) LOAD

     Currency,

     date(max(Date)) as Date,

     1 as #LastDateFlag

RESIDENT data

GROUP BY Currency

;

Then your chart would be:

Dimension: Currency, Date

Expression: only({<#LastDateFlag={1}>} Rate)

Regards,

Vlad

Anonymous
Not applicable
Author

Hello Vlad

I cant get it to work, i tried the script below but it wont give me a correct answer.

It gives me a new field with the last ratedate for each currancy and for every row in the database, but i only want one row for each currancy with the rate from the last inputdate and i need this to be done directly in the script, not in a chart with an expression.

Can this be done??

Lastrate:

LOAD

     CUCUCD,
    
CUARAT,
    
CUCUTD,
    
CUCRTP;
SQL SELECT CUCUCD,
    CUCUTD,
    CUARAT,
    CUCRTP
FROM "CAO_PROD".MVXJDTA.CCURRA;
Left JOIN (Lastrate)
LOAD
    
CUCUCD,
    
max(Date(Date#([CUCUTD],'YYYYMMDD'),'YYYY-MM-DD')) as Date,
     1
as #LastDateFlagRESIDENT LastrateGROUP BY CUCUCD

""CUCUCD is Currency CUARAT is Rate CUCUTD is Date like(YYYYMMDD) and CUCRTP is Changenr.""

anderslinden
Partner - Contributor III
Partner - Contributor III

Hi! This may not be the most beautiful solution but it seems to work. Note that my date format is not the same as yous so you might have to work with your date formatting to get the join to work properly.

OriginTable:

LOAD CUCUCD,
CUARAT,
CUCUDT,
CUCRTP
FROM
CurrencyTables.xlsx
(
ooxml, embedded labels, table is Blad1)
;
FinalTable:
LOAD CUCUCD,
max(CUCUDT) as MaxCUCUDT
resident OriginTable
group by CUCUCD ;

left join (FinalTable)
load CUCUCD,
CUCUDT as MaxCUCUDT,
max(CUCRTP) as MaxCUCRTP
resident OriginTable
group by CUCUCD,CUCUDT ;

left join (FinalTable)
load CUCUCD,
CUCUDT as MaxCUCUDT,
CUCRTP as MaxCUCRTP,
CUARAT as LastRate
resident OriginTable
;
drop table OriginTable;

Regards, Anders

BI Consultant, Business Information Providers
www.bipab.se
Anonymous
Not applicable
Author

Thank you Anders!

It works fine after formating the dates.

Now im a very happy guy.

Once again Thanks!!

Patric