bi power 两个日期挑较早的日期_PowerBI中按日期排列的多对多关系

I need to be able to calculate a measure in a table of many to many relationship. Here are my two tables:

Contracts Table

Serial# ContractTyp StartDate EndDate

A MP 1/1/2017 1/6/2018

B ML 10/24/2017 6/30/2020

A ML 1/6/2018 12/30/2019

C MU 5/15/2018 1/1/2021

Performance Table

Serial# Diff Good Bad Date

A 15 1 0 1/30/2017

B -24 1 0 12/17/2017

A 57 0 1 4/22/2017

A 18 1 0 2/1/2018

C 123 0 1 9/12/2018

So, my measure is simple. It just calculates the percentage of Good by Serial#.

NUM_GOOD = CALCULATE(COUNTA('Performance'[Good]),'Performance[Good] IN {"1"})

NUM_BAD = CALCULATE(COUNTA('Performance'[Bad]),'Performance[Bad] IN {"1"})

PERFORMANCE_METRIC = NUM_GOOD/(NUM_BAD + NUM_GOOD)

I need to be able to run that performance metric for every Serial# but only for when the machines were under a MP or MU ContractTyp. So I need it to be able to look at the Date in the Performance Table and make sure that date falls in the range between StartDate and EndDate on the Contracts Table where Serial# is MP or MU.

So I for example if I want to look at the Performance of all Serial#'s with a ContractTyp of MP or MU in the last 2 years I would want the result to look as follows:

Serial# PERFORMANCE_METRIC

A 50%

B 100%

C 0%

Thanks in advance!

解决方案

Below is a formula for a Calculated Column that you could add to the Performance table to return the True / False values (ref your comments).

To explain the logic:

Store the Serial and Date values (from the current record) in variables.

If we find at least 1 matching Contract with the required ContractTyp and Date range, return True, otherwise False.

Has Contract =

VAR vSerial = [Serial#]

VAR vDate = [Date]

RETURN

IF (

CALCULATE (

COUNTROWS ( Contracts ),

Contracts[Serial#] = vSerial,

Contracts[ContractTyp] IN { "MP", "MU" },

Contracts[StartDate] <= vDate,

Contracts[EndDate] >= vDate

) > 0,

TRUE (),

FALSE ()

)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值