PowerBI 加入 table 和计算

PowerBI join table and calculation

我有两个表: Table 1

Year Name Score
2010 A    1000
2011 A    1200
2012 A    1200
2013 A    1300
2010 B    1100
2011 B    1500
2012 B    1300
2013 B    1600

Table 2

Year Factor
2010 3.57
2011 4.21
2012 6.11
2013 2.15

我想这样做:匹配两个表,只要Year in Table 1匹配Year in Table 2,将分数除以因子,例如对于 A2010, 1000/3.57 中;对于 B2010,1100/3.57

如何修改以下代码?

adjusted score  = 
VAR
filter (all('Table 1'[Year]), 'Table 1'[Year]='Table 2'[Year])
RETURN
DIVIDE ('Table 1' [Score], 'Table 2'[Factor')

非常感谢!

如果您正在寻找 措施,您可以尝试下面的代码-

adjusted score = 

VAR current_row_year = MIN('Table 1'[Year])
VAR current_row_Score = MIN('Table 1'[Score])

VAR factor =
CALCULATE(
    MAX('Table 2'[Factor'),
    filter (
        all('Table 2'), 
        'Table 2'[Year]= current_row_year
    )
) 

RETURN DIVIDE (current_row_Score, factor)

自定义列的代码如下-

adjusted score = 

VAR current_row_year = 'Table 1'[Year]
VAR current_row_Score = 'Table 1'[Score]

VAR factor =
CALCULATE(
    MAX('Table 2'[Factor'),
    filter (
        all('Table 2'), 
        'Table 2'[Year]= current_row_year
    )
) 

RETURN DIVIDE (current_row_Score, factor)

You can also do the same using Transformation using Power query. In that case you have to just merge your table 1 and 2 using Year and then after Expanding the table, you will have Factor in each row for the Year. You can then just add a new custom column with - Score/Factor