Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I'm attempting to perform a column calculation that will return a value based on the last date of an instrument calibration prior to a quality control check. I have two tables, Calibration and QC, which are related by instrument serial number. For each instrument, there may be multiple calibration dates and quality control checks, during which a result (Xq) is generated. The calculated column (cal check) should compare the difference between the QC check Xq and the Xq result of the last calibration prior to that check.
Example:
Calibration
Serial | Cal Date | Cal Xq |
100141 | 12/5/19 14:12 | 0.081 |
100141 | 4/12/15 11:36 | 0.085 |
100290 | 6/16/15 9:19 | 0.077 |
100321 | 1/21/19 14:44 | 0.082 |
100321 | 1/21/19 11:12 | 0.079 |
100670 | 1/2/20 11:24 | 0.079 |
100670 | 9/4/18 15:39 | 0.081 |
QC
Serial | QC Date | Cal Date | QC Xq | Cal Check |
100141 | 6/15/19 | 4/12/2015 | 0.081 | -4.71% |
100141 | 10/15/19 | 4/12/2015 | 0.082 | -3.53% |
100141 | 2/15/20 | 12/5/2019 | 0.079 | -2.47% |
100141 | 6/15/20 | 12/5/2019 | 0.08 | -1.23% |
100290 | 6/15/19 | 6/16/2015 | 0.079 | 2.60% |
100290 | 10/15/19 | 6/16/2015 | 0.078 | 1.30% |
100290 | 2/15/20 | 6/16/2015 | 0.077 | 0.00% |
100290 | 6/15/20 | 6/16/2015 | 0.077 | 0.00% |
100321 | 6/15/19 | 1/21/2019 | 0.08 | -2.44% |
100321 | 10/15/19 | 1/21/2019 | 0.081 | -1.22% |
100321 | 2/15/20 | 1/21/2019 | 0.079 | -3.66% |
100321 | 6/15/20 | 1/21/2019 | 0.082 | 0.00% |
100670 | 6/15/19 | 9/4/2018 | 0.079 | -2.47% |
100670 | 10/15/19 | 9/4/2018 | 0.077 | -4.94% |
100670 | 2/15/20 | 1/2/2020 | 0.082 | 3.80% |
100670 | 6/15/20 | 1/2/2020 | 0.081 | 2.53% |
Fortunately, there is a helper column in the QC table that lists when the last cal was performed. Unfortunately, it is just a date with no time stamp, whereas the Cal Date column in the Calibration table does include the time, and there may be multiple entries from the same day. If I were doing this in Excel, I would use an array to match serial number and cal date between the two tables to return the appropriate Cal Xq, and calculate the difference from there. If they are sorted newest-to-oldest in the table, it will give me the correct result. But, I'm new to Power BI and haven't found a comparable method of doing this with DAX.
Any help would be appreciated, thank you!
Solved! Go to Solution.
Hi @Anonymous ,
here are two calc Columns that I think do the trick
last Cal Xq val =
var serial = [Serial]
var calDate = [QC Date]
var maxDate = CALCULATE(MAX('Calibration'[Cal Date]), FILTER(Calibration, Calibration[Serial] = 'QC'[Serial] && Calibration[Cal Date] <= calDate ))
return
CALCULATE(MAX('Calibration'[Cal Xq]), FILTER('Calibration', Calibration[Serial] = serial && Calibration[Cal Date] = maxDate))
var = DIVIDE([QC Xq], [last Cal Xq val])-1
Hope this Helps
Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!
Proud to be a Super User!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
95 | |
76 | |
65 | |
51 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |