Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
snifer
Post Patron
Post Patron

2 different table correlation of 3 columns

I need to find out how to find the right result for the two column exchange rate and avg.rate based on the match of column "month" "year" and "currency" 

           
Economic     change in DKK   
           
amountcurrencymonthyear  currencymonth yearexchange rateavg. rate
10EUR12018  EUR120181.51.3
20CZK22018  CZK2201877.5
           
result          
amountcurrencymonthyear exchange rateavg. rate     
10EUR120181.51.3     
20CZK2201877.5     
1 ACCEPTED SOLUTION

@snifer

 

NewColumnExRate = 
LOOKUPVALUE (
    'change in DKK'[exchange rate],
   'change in DKK'[currency], 'Economic'[currency],
    'change in DKK'[month], 'Economic'[month],
    'change in DKK'[year], 'Economic'[year],
    'change in DKK'[source], "actual"
)

View solution in original post

23 REPLIES 23
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @snifer,

 

By my tests, the solution of AlB and Williamspsouza should be helpful.

 

You could download my attachment which is my test pbix. You could see the detail steps under APPLIED steps in Query Editor about Merge query.

 

In addition, you could create the calculated column with LOOKUPVALUE fucntion like below.

 

 

NewColumnExRate = 
LOOKUPVALUE (
    'change in DKK'[exchange rate],
   'change in DKK'[currency], 'Economic'[currency],
    'change in DKK'[month ], 'Economic'[month],
    'change in DKK'[year], 'Economic'[year]
)

NewColumnAveRate = 
LOOKUPVALUE (
    'change in DKK'[avg. rate],
   'change in DKK'[currency], 'Economic'[currency],
    'change in DKK'[month ], 'Economic'[month],
    'change in DKK'[year], 'Economic'[year]
)

In addition, based on the syntax of LOOKUPVALUE, it allows more than one search_columnName and search_value.

 

 

 

LOOKUPVALUE( <result_columnName>, <search_columnName>, <search_value>[, <search_columnName>, <search_value>]…)

Here is the output for two solutions.

result.PNG

 

 

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

change in DKK    
      
currencymonth yearexchange rateavg. ratesource
EUR120181.51.3actual 
CZK2201877.5actual
EUR1201821budget
CZK220187.17.6budget

the problem was I didn't notice there was an extra column specifying the source of the exchange rate ( there are double result based on different source)

2 solutions:

 

or I split the table into 2 different tables based on source column

 

or better can I modify the code

NewColumnExRate = 
LOOKUPVALUE (
    'change in DKK'[exchange rate],
   'change in DKK'[currency], 'Economic'[currency],
    'change in DKK'[month ], 'Economic'[month],
    'change in DKK'[year], 'Economic'[year]
)

adding the possibility to take just one parameter of source like "actual"I

what I should use early or filter?

Hi @snifer,

 

Have you solved your problem?

 

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If you still need help, please feel free to ask.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@snifer

 

NewColumnExRate = 
LOOKUPVALUE (
    'change in DKK'[exchange rate],
   'change in DKK'[currency], 'Economic'[currency],
    'change in DKK'[month], 'Economic'[month],
    'change in DKK'[year], 'Economic'[year],
    'change in DKK'[source], "actual"
)
AlB
Super User
Super User

@snifer

 

I'm not sure what you did. I just ran a quick test and it does work as expected.

Anonymous
Not applicable

Hi @snifer,

 

Have you tried the old school method; Create a calculated column concatenating currency, month and year and linking the tables by this created calculated column?

 

Best,

David

Anonymous
Not applicable

If both tables are connected and there is 1 to 1, you can use two calculated columns: 1. Related(avg.rate) 2. Related(exchange rate)

the table can be connected, so only option look to be lookup with 3 condition, but i can't make it work

Anonymous
Not applicable

You can use "Merge Query as new" and add two columns... let Source = Table.NestedJoin(Economic,{"currency"},#"change in DKK",{"currency"},"change in DKK",JoinKind.LeftOuter), #"Expanded change in DKK" = Table.ExpandTableColumn(Source, "change in DKK", {"exchange rate", "avg. rate"}, {"change in DKK.exchange rate", "change in DKK.avg. rate"}) in #"Expanded change in DKK"

merging a query you can do based on 1 column not in 3

Anonymous
Not applicable

You can base on 3... let Source = Table.NestedJoin(Economic,{"currency", "month", "year"},#"change in DKK",{"currency", "month ", "year"},"change in DKK",JoinKind.LeftOuter), #"Expanded change in DKK" = Table.ExpandTableColumn(Source, "change in DKK", {"exchange rate", "avg. rate"}, {"change in DKK.exchange rate", "change in DKK.avg. rate"}) in #"Expanded change in DKK"

what is the exact problem with LOOKUPVALUE()??

@snifer

Column for exchange rate in Table1 (the one you show under 'economic'). I haven't tested but it should work

 

 

NewColumnExRate =
LOOKUPVALUE (
    Table2[exchange rate],
    Table2[Currency], Table1[Currency],
    Table2[Month], Table1[Month],
    Table2[Year], Table1[Year]
)

 

based on you formula i create the one

NewColumnAVG-rate = LOOKUPVALUE ( ExchangeRates[DefaultAvgRate], ExchangeRates[CurrencyCode], ConsolidatedAccounts[CurrencyCode], ExchangeRates[Month], ConsolidatedAccounts[Month], ExchangeRates[Year], ConsolidatedAccounts[Year] )

 

 

but return an empty column

It accept just fir column then it doesn't take in consideration other 2,

 

can someone code this with lookup and all 3 columns?

@snifer

Ok, can you just show what you tried with LOOKUPVALUE that does not work and the error message you get?

no error, just not working get wrong value,,

 

can you try yourself lookup in the example and if work posting to me

Anonymous
Not applicable

Are you sure? I have tried here and it did work. This formula consider all 3 columns.. it's a merge....

im not familiar with merge by formula usually i use the interface, how i can merge with the formula?

Anonymous
Not applicable

Edit Queries (in the query editor) Select the table Economic then Merge Query as New. In the Merge window then select "Economic" and all 3 columns then select the second table "change in DKK" and all 3 columns also, then click "ok"... the new table contains everything you need.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.