Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Guys,
I would like to know if there is a function, similar to apply map, but that uses more than one condition to find a value in a table.
I have a reference table called RESSOURCE and a main table called MAIN, like this:
RESSOURCE:
NAME | RATE | START DATE | END DATE
-----------------------------------------------------
MAIN:
NAME| DATE |HOURS
MAIN has multiple rows with worked hours for a ressource and I want to know, how much that work costed. For that reason I want to create a field EUR that would be the result of HOURS (from MAIN) and RATE (from RESSOURCE) in my MAIN table.
The thing is, one ressource has multiple rates in RESSOURCE, with a start date and end date. I need to take the RATE, which has start and end date matching field DATE in MAIN.
For exemple: if I want to know how much costed John's work in 15.04.2019:
NAME| DATE |HOURS
John | 15.04.2019| 8h
I need to find a row in my table RESSOURCE, with the rate that was valid in that day. So if I have for John these 3 possibilities in RESSOURCE, my expression will return the rate in second position:
NAME | RATE | START DATE | END DATE
John | 25€ | 01.01.2019 | 31.03.2019
John | 40€ | 01.04.2019 | 31.07.2019
John | 40€ | 01.08.2019 | 31.10.2019
Thant means that if my function finds the name John in RESSOURCE, but the SART DATE and END DATE dont match DATE in MAIN, it has to keep searching until find a row that the 3 fields correspond or return a default value indicating that my conditions could be satisfied (there is no rate for that ressource within that period of time).
Can somebody help me?:)
from the screenshot it looks as if you are doing a qualify operation. (column name is ResourceNew.Name)
as i dont know what you have done ; hard to comment.
attached is the qvf file
You need to join the tables using interval match function
basically interval match matches your date field in main to appropriate row in Resource based on start and end date (between the dates)
check below links for an overview
https://community.qlik.com/t5/Qlik-Design-Blog/IntervalMatch/ba-p/1464547
https://community.qlik.com/t5/QlikView-Documents/Interval-Match-Feature-Function/ta-p/1477919
that would need a few additional steps
see below
MAIN:
load * Inline [
NAME, DATE ,HOURS
John , 15/04/2019, 8
];
RESOURCE:
load * inline [
NAME , RATE , START DATE , END DATE
John , 25 , 01/01/2019 , 31/03/2019
John , 40 , 01/04/2019 , 31/07/2019
John , 40 , 01/08/2019 , 31/10/2019
];
//interval match on date and name
ResourceNew:
IntervalMatch (DATE,NAME)
Load distinct [START DATE], [END DATE], NAME resident RESOURCE;
//you will get multiple synthetic keys and circular references
// to avoid that load the rate into the table created with interval match
left Join(ResourceNew)
load * resident RESOURCE;
drop table RESOURCE;
My ResourceNew is then empty (look screenshot)
You were right, the date format was a problem, but still not that. 😞
I changed the data a little bit, but the script is the same:
result screenshot