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!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…