简体   繁体   English

具有DAX公式的Power BI动态列参考

[英]Power BI dynamic column reference with DAX formula

I have a Orders and ExchangeRates tables connected via a date key: 我有一个通过date键连接的OrdersExchangeRates表:

在此处输入图片说明

在此处输入图片说明

What I am trying to do is to fetch the correct currency exchange rate from ExchangeRates , which are organized in columns, with the column name matching the currency codes from Orders . 我想做的是从ExchangeRates获取正确的货币汇率, ExchangeRates按列组织,列名称与Orders的货币代码匹配。

I'm basically trying to make a dynamic column reference to the EUR or JPY columns by using the matching Orders[orderCurrency] like this: 我基本上是想通过使用匹配的Orders[orderCurrency]这样来对EURJPY列进行动态列引用:

orderExchangeRate = LOOKUPVALUE(ExchangeRates[Orders[orderCurrency]],
ExchangeRates[date],Orders[date])

or: 要么:

orderExchangeRage = SELECTCOLUMNS(ExchangeRates,Orders[orderCurrency], ....)

But none of the functions accept a dynamic column reference, they expect the actual name of the column 但是没有一个函数接受动态列引用,它们期望列的实际名称

How can I dynamically refer to the EUR and JPY columns based on Orders[orderCurrency] ? 如何基于Orders[orderCurrency]动态引用EURJPY列? Isn't there something similar to INDIRECT to make a dynamic reference in PowerBI? 在PowerBI中没有类似于INDIRECT的动态引用吗?

As far as I know, there is no such function as INDIRECT in DAX. 据我所知,在DAX中没有INDIRECT这样的功能。

You have (at least) two options: 您(至少)有两个选择:

  • If it's just EUR and JPY, you could create two formulas and based on the currency switch between them with IF() or SWITCH(). 如果只是EUR和JPY,则可以使用IF()或SWITCH()创建两个公式,并基于它们之间的货币切换。 Like: If (Currency = "EUR", LOOKUPVALUE(EUR), LOOKUPVALUE(JPY). Pseudo code, of course. 像:如果(货币=“ EUR”,LOOKUPVALUE(EUR),LOOKUPVALUE(JPY)。伪代码,当然。

  • Unpivot the EUR and JPY column in the ExchangeRate table. 取消透视ExchangeRate表中的EUR和JPY列。 Then you'll have a line for each date and currency, and you can reference it as you like. 然后,您将在每个日期和货币上都有一行,您可以根据需要引用它。 Especially usefull with more currency combinations. 与更多的货币组合特别有用。 You can Unpivot in the Query Editor, Transformation Tab. 您可以在查询编辑器的“转换”选项卡中取消透视。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM