Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
FranciscoQ
Partner - Creator
Partner - Creator

Last hour of every day value related

Hi !

 

I need some help with this:

I have a a Currency Exchange database, that show values for each hour of each day, the thing is that I need the value related to the last hour of each day.

 

Ex:

Day                                                         CE

10/01/2020 ,     10:00                        2,32 

10/01/2020 ,     10:55                        2,33

10/01/2020 ,     11:04                        2,35

.......                         ........... 

And what I need is:

Day                            Time                        CE

10/01/2020            22:05                        2,36

11/01/2020            21:07                        2,41

.......                         ...........                        ..........

 

 

So I've tried with the next Script:

 

CE_temp:
LOAD

Day,
Timestamp(Day,'hh:mm') AS Time,
CE,

FROM [lib://DEV_STG_WEB/QVD/STG_WEB_CE.QVD]
(qvd);

 

Left Join(CE_temp)
Load
Day,
Max(Time) AS Max_Hour,
1 AS Flag_max_hour
Resident CE_temp

Group By Day;

 

So I can detect then all the values with flag_max_hour = 1, and I can create another table filtering those values

 

The problem is that I am noticing that It's putting flag_max_hour for every hour ! Not just the max hour,

So I have

Day                      Hour            CE            Flag_max_hour                                              

10/01/2020      10:00          2,32                       1

10/01/2020      10:55          2,33                       1

10/01/2020      11:04          2,35                       1

 

 

I would really appreciate some help!

1 Solution

Accepted Solutions
Vegar
MVP
MVP

Try adjusting your script to this.

CE_temp:
LOAD
Day,
Timestamp(Day,'hh:mm') AS Time,
CE
FROM [lib://DEV_STG_WEB/QVD/STG_WEB_CE.QVD]
(qvd);

Left Join(CE_temp)
Load
Day,
Max(Time) AS Time,
1 AS Flag_max_hour
Resident CE_temp

Group By Day;

If you want to skip the Flag and reduce directly in the join, then you can replace the Left Join with Right Join or with Inner Join to achieve this. Like this.

CE_temp:
LOAD
Day,
Timestamp(Day,'hh:mm') AS Time,
CE
FROM [lib://DEV_STG_WEB/QVD/STG_WEB_CE.QVD]
(qvd);

Inner Join(CE_temp)
Load
Day,
Max(Time) AS Time
//,1 AS Flag_max_hour
Resident CE_temp

Group By Day;

View solution in original post

3 Replies
Vegar
MVP
MVP

Try adjusting your script to this.

CE_temp:
LOAD
Day,
Timestamp(Day,'hh:mm') AS Time,
CE
FROM [lib://DEV_STG_WEB/QVD/STG_WEB_CE.QVD]
(qvd);

Left Join(CE_temp)
Load
Day,
Max(Time) AS Time,
1 AS Flag_max_hour
Resident CE_temp

Group By Day;

If you want to skip the Flag and reduce directly in the join, then you can replace the Left Join with Right Join or with Inner Join to achieve this. Like this.

CE_temp:
LOAD
Day,
Timestamp(Day,'hh:mm') AS Time,
CE
FROM [lib://DEV_STG_WEB/QVD/STG_WEB_CE.QVD]
(qvd);

Inner Join(CE_temp)
Load
Day,
Max(Time) AS Time
//,1 AS Flag_max_hour
Resident CE_temp

Group By Day;

FranciscoQ
Partner - Creator
Partner - Creator
Author

That worked perfect !

 

Thank you very much!

Vegar
MVP
MVP

Glad I could help.