简体   繁体   English

在Power BI模型中没有明显关系的情况下计算2个表之间的月度值

[英]Calculate monthly value between 2 tables without an explicit relationship in Power BI model

I am trying to create a measure that calculates (a/qty)*100 for each month, where qty commes from Delivery table (generated with an R script) 我正在尝试创建一个度量值,该度量值每个月计算(a /数量)* 100,其中“数量”来自交付表(使用R脚本生成)

  month        qty
  <date>     <dbl>
1 2019-02-01     1
2 2019-03-01   162
3 2019-04-01  2142
4 2019-05-01   719

And a comes from a table TABLE_A that has been created within Power BI that looks like this : 一个来自于已经双向电力,看起来像这样内创建一个表TABLE_A:

Client     Date            a
x          2019-03-07      3
x          2019-04-14      7
y          2019-03-12      2

So far, I managed to calculate that value overall with the following measure formula : 到目前为止,我设法通过以下度量公式总体上计算了该值:

MEASURE = CALCULATE( (Sum(TABLE_A[a])/sum(Delivery[qty]))*100)

The issue I have is that I would need this measure monthly (ie join the tables on month) without explicitly defining a link between the tables in the PowerBI model. 我遇到的问题是,我每月需要此度量(即每月加入表),而无需在PowerBI模型中的表之间明确定义链接。

For each row in TABLE_A you need to look up the corresponding qty in Delivery , so try something along these lines: 对于TABLE_A每一行,您需要在Delivery查找相应的qty ,因此请尝试以下方式:

MEASURE =
DIVIDE(
    SUM( TABLE_A[a] ),
    SUMX(
        TABLE_A,
        LOOKUPVALUE(
            Delivery[qty],
            Delivery[month], EOMONTH( TABLE_A[Date], -1 ) + 1
        )
    )
) * 100

The formula EOMONTH( TABLE_A[Date], -1 ) returns the end of the previous month relative to that date and adding 1 day to that to get the start of the current month for that date. 公式EOMONTH( TABLE_A[Date], -1 )返回相对于该日期的上月末,并在该日期后加上1天以获取该日期的当前月的开始。

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

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