Forum Discussion
Filtering a matrix column by another column or by TopN
- Anonymous4 years ago
HI ReadTheIron,
You can use the following measure formula to check the last 3 report dates which are after 'Remediation Date' and grouped based on the current 'common name', then you can use it on matrix 'visual level filter' to filter records:
Flag = VAR _currAssetDate = CALCULATE ( MAX ( AssetTable[Remediation] ), ALLSELECTED ( FailureTable ), VALUES ( AssetTable[Common Name] ) ) VAR currReportDate = MAX ( FailureTable[Date Reported] ) VAR _list = CALCULATETABLE ( VALUES ( FailureTable[Date Reported] ), FILTER ( ALL ( FailureTable ), [Date Reported] >= _currAssetDate ), VALUES ( FailureTable[Common Name] ) ) VAR ranked = FILTER ( ADDCOLUMNS ( _list, "Rank", RANKX ( _list, [Date Reported],, DESC ) ), [Rank] <= 3 ) RETURN IF ( currReportDate IN SELECTCOLUMNS ( ranked, "Date", [Date Reported] ), currReportDate )
Regards,Xiaoxin Sheng
Here's some dummy data that should give the matrix in the original question:
AssetTable
| Common Name | Remediation | Date of Last Failure | Latest Failure Date After Remediation |
| BMT-J2-291A | 6/27/2021 | 7/24/2021 | 7/24/2021 |
| IRT-L1-203 | 5/22/2021 | 8/31/2021 | 8/31/2021 |
| BMT-Q1-471 | 7/17/2021 | 7/14/2021 |
And FailureTable
| Common Name | Date Reported | Cause Code |
| IRT-L1-203 | 8/31/2021 | No Cause Found |
| BMT-J2-291A | 7/24/2021 | No Applicable Cause Code Found |
| BMT-Q1-471 | 7/14/2021 | No Cause Found |
| BMT-Q1-471 | 7/5/2021 | No Cause Found |
| IRT-L1-203 | 6/21/2021 | Debris |
| BMT-J2-291A | 6/2/2021 | No Cause Found |
| BMT-Q1-471 | 3/27/2021 | Worn |
| BMT-J2-291A | 3/25/2021 | Grounded |
| BMT-J2-291A | 3/18/2021 | Grounded |
| IRT-L1-203 | 3/18/2021 | Out of adjustment |
| IRT-L1-203 | 2/24/2021 | No Cause Found |
| BMT-J2-291A | 2/8/2021 | No Cause Found |
| BMT-J2-291A | 2/1/2021 | Weather |
| BMT-Q1-471 | 12/17/2020 | Out of adjustment |
| BMT-J2-291A | 12/16/2020 | No Cause Found |
| IRT-L1-203 | 10/7/2019 | No Cause Found |
| IRT-L1-203 | 10/5/2019 | Age |
| BMT-J2-291A | 1/3/2019 | Age |
Date of Last Failure is a calculated column drawing data from FailureTable.
The matrix is filtered based on whether Latest Failure Date After Remediation is not blank.
I'm not sure what I'm doing wrong in trying to create a calculated column referencing both these tables, any help appreciated!
HI ReadTheIron,
You can use the following measure formula to check the last 3 report dates which are after 'Remediation Date' and grouped based on the current 'common name', then you can use it on matrix 'visual level filter' to filter records:
Flag =
VAR _currAssetDate =
CALCULATE (
MAX ( AssetTable[Remediation] ),
ALLSELECTED ( FailureTable ),
VALUES ( AssetTable[Common Name] )
)
VAR currReportDate =
MAX ( FailureTable[Date Reported] )
VAR _list =
CALCULATETABLE (
VALUES ( FailureTable[Date Reported] ),
FILTER ( ALL ( FailureTable ), [Date Reported] >= _currAssetDate ),
VALUES ( FailureTable[Common Name] )
)
VAR ranked =
FILTER (
ADDCOLUMNS ( _list, "Rank", RANKX ( _list, [Date Reported],, DESC ) ),
[Rank] <= 3
)
RETURN
IF ( currReportDate IN SELECTCOLUMNS ( ranked, "Date", [Date Reported] ), currReportDate )
Regards,
Xiaoxin Sheng
- ReadTheIron4 years ago
Helper III
That works beautifully! I'll be studying it to figure out how it works - thank you for sharing your expertise; it's really helping me learn.