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: 
Aspiring_Developer
Creator III
Creator III

Applymap using keys

Hello Everyone,

Can anyone please help me with the below scenario:-

Table A

YearEntity Reporting CurrencyExchange Rate
2021ARS10
2021USD50
2021EUR70

 

Table B

YearEntity CodeEntity nameCountryEntity Reporting CurrencyAmountNew AmountAs per the currency (to be calculated)
2021ARS201USAUSA480 
2021USD226EuropeEUR490 
2021EUR501ArgentinaARS500

 

 

I want to calculate the new amount as per the currency rate from table A

I tried using Apply map by creating a key in table A as mapping load Year & entity reporting currency as key, exchange rate from table A

Not sure how can we implement apply in table B to calculate the new amount as per exchange rate from table A

Can anyone please help ?

Thank You

 

2 Solutions

Accepted Solutions
QFabian
Specialist III
Specialist III

Hi @Aspiring_Developer , please try this :

[Table A]:
Load * INLINE [
Year, Entity Reporting Currency, Exchange Rate
2021, ARS, 10
2021, USD, 50
2021, EUR, 70];

MapTable:
mapping
Load
Year & ' | ' & [Entity Reporting Currency] as YEarEntity,
[Exchange Rate]
Resident [Table A];

[Table B]:
Load * INLINE [
Year, Entity Code, Entity name, Country, Entity Reporting Currency, Amount
2021, ARS, 201, USA, USA, 480
2021, USD, 226, Europe, EUR, 490
2021, EUR, 501, Argentina, ARS, 500 ];

NewTable:
Load
*,
Amount * ApplyMap('MapTable', Year & ' | ' & [Entity Code]) as NewAmount
Resident [Table B];
drop table [Table A];
drop table [Table B];

QFabian

View solution in original post

lironbaram
Partner - Master III
Partner - Master III

Hi ,

use this script it will give you the result you look for.

ratemap:
mapping load Year&'_'&"Entity Reporting Currency" as key,
             "Exchange Rate"					  as exRate;
load * inline [
Year,	Entity Reporting Currency,	Exchange Rate
2021,	ARS,	10
2021,	USD,	50
2021,	EUR,	70
];
 


Table2:
load *,
     applymap('ratemap', Year&'_'&"Entity Reporting Currency") * Amount as NewAmount;
load * inline [
Year,	Entity Code,	Entity name,	Country,	Entity Reporting Currency,	Amount
2021,	ARS,	201,	USA,	USD,	480	 
2021,	USD,	226,	Europe,	EUR,	490	 
2021,	EUR,    501,	Argentina,	ARS,	500	
];

View solution in original post

7 Replies
QFabian
Specialist III
Specialist III

Hi @Aspiring_Developer , please try this :

[Table A]:
Load * INLINE [
Year, Entity Reporting Currency, Exchange Rate
2021, ARS, 10
2021, USD, 50
2021, EUR, 70];

MapTable:
mapping
Load
Year & ' | ' & [Entity Reporting Currency] as YEarEntity,
[Exchange Rate]
Resident [Table A];

[Table B]:
Load * INLINE [
Year, Entity Code, Entity name, Country, Entity Reporting Currency, Amount
2021, ARS, 201, USA, USA, 480
2021, USD, 226, Europe, EUR, 490
2021, EUR, 501, Argentina, ARS, 500 ];

NewTable:
Load
*,
Amount * ApplyMap('MapTable', Year & ' | ' & [Entity Code]) as NewAmount
Resident [Table B];
drop table [Table A];
drop table [Table B];

QFabian
lironbaram
Partner - Master III
Partner - Master III

Hi ,

use this script it will give you the result you look for.

ratemap:
mapping load Year&'_'&"Entity Reporting Currency" as key,
             "Exchange Rate"					  as exRate;
load * inline [
Year,	Entity Reporting Currency,	Exchange Rate
2021,	ARS,	10
2021,	USD,	50
2021,	EUR,	70
];
 


Table2:
load *,
     applymap('ratemap', Year&'_'&"Entity Reporting Currency") * Amount as NewAmount;
load * inline [
Year,	Entity Code,	Entity name,	Country,	Entity Reporting Currency,	Amount
2021,	ARS,	201,	USA,	USD,	480	 
2021,	USD,	226,	Europe,	EUR,	490	 
2021,	EUR,    501,	Argentina,	ARS,	500	
];
PrashantSangle

another approach than applymap is you can achieve this in front end also. Just create composite key in back end.

 

and in front end (designer window) 

add expression > amount * exchange rate

 

Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Aspiring_Developer
Creator III
Creator III
Author

Hi, Thank you for your response

Can we achieve it without taking inline table as we have exchange rate for different rates 2019,2020,2021 .

Thanks in advance

Aspiring_Developer
Creator III
Creator III
Author

Hello,

The above one worked, however, there is one currency which is not available in mapping table (ex EUR), but it is present in data table.

Since, we have used apply map, it should not return any value as we do not have EUR exchange rate in the file.

I tried this 

"Amount in Entity Reporting Currency" / ApplyMap('Map_table', "Year" & ' | ' & "Entity Reporting Currency",'NA') as NewAmount

But still it is populating incorrect values instead of "NA".

Please help

QFabian
Specialist III
Specialist III

Hi @Aspiring_Developer !, i made the inlines just because  there is no another sample of data

QFabian
Aspiring_Developer
Creator III
Creator III
Author

hello,

thank you. Yes i did the same by loading the excel file.

However, it giving me some incorrect values as i do not have the exchange rate for EUR in mapping file, but i have the data for EUR in data file. so it should not return any value

Can you please help ?