Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ReadTheIron
Helper III
Helper III

Filtering a matrix column by another column or by TopN

I'm presenting data in a matrix that looks like this:

 

ReadTheIron_0-1640700809889.png

 

I would like to display all rows where Date Reported is after Remediation. Ideally I would like to display all rows where Date Reported is after Remediation, and the first Date Reported before Remediation. Failing that, I would like to display the rows with the three latest Date Reported. I've been playing around with TopN but haven't gotten anywhere. Can anyone point me in the right direction? Many thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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 )

2.png
Regards,

Xiaoxin Sheng

View solution in original post

7 REPLIES 7
ReadTheIron
Helper III
Helper III

@amitchandak, @HashamNiaz , thank you for the help! Unfortunately I run into the same issue when I try either solution - I can't write a measure or a DAX expression that references two tables. Date Reported comes from one table (call it FailureTable), all of the other fields from another (call it AssetTable). The two tables are related many-to-one on Common Name.

 

So if I try creating a measure, I can get as far as =countrows(filter(FailureTable,FailureTable[Date Reported], but then I can't enter AssetTable[Remediation].

 

If I try adding a calculated column to AssetTable, I can't enter FailureTable.

Anonymous
Not applicable

Hi @ReadTheIron,

In fact, DAX expressions can be calculated or invoked across multiple tables.

Power BI DAX How to Summarize Data From Multiple Tables - Plainly Blog - Data Modelling, Advanced An...

Can you please share some dummy data that keep the raw data structure and expected results to paste here with table format? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Here's some dummy data that should give the matrix in the original question:

AssetTable

Common NameRemediationDate of Last FailureLatest Failure Date After Remediation
BMT-J2-291A6/27/20217/24/20217/24/2021
IRT-L1-2035/22/20218/31/20218/31/2021
BMT-Q1-4717/17/20217/14/2021 

 

And FailureTable

Common NameDate ReportedCause Code
IRT-L1-2038/31/2021No Cause Found
BMT-J2-291A7/24/2021No Applicable Cause Code Found
BMT-Q1-4717/14/2021No Cause Found
BMT-Q1-4717/5/2021No Cause Found
IRT-L1-2036/21/2021Debris
BMT-J2-291A6/2/2021No Cause Found
BMT-Q1-4713/27/2021Worn
BMT-J2-291A3/25/2021Grounded
BMT-J2-291A3/18/2021Grounded
IRT-L1-2033/18/2021Out of adjustment
IRT-L1-2032/24/2021No Cause Found
BMT-J2-291A2/8/2021No Cause Found
BMT-J2-291A2/1/2021Weather
BMT-Q1-47112/17/2020Out of adjustment
BMT-J2-291A12/16/2020No Cause Found
IRT-L1-20310/7/2019No Cause Found
IRT-L1-20310/5/2019Age
BMT-J2-291A1/3/2019Age

 

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!

Anonymous
Not applicable

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 )

2.png
Regards,

Xiaoxin Sheng

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.

HashamNiaz
Solution Sage
Solution Sage

Hi @ReadTheIron !

To solve this issue, you first needs to create a column which calculates either [Date Reported] is greater than [Remediation] or not. You can create calculated column for that purpose using below DAX;

 

IsDateReport = IF(Table[DateReported] > Table[Remediation], 1, 0)

 

After this you will need to create a Ranking measure, which will Rank based your column selection like (Common Name, Remediation), this will create Ranking, now you can use this measure to filter out only Top 3 Ranks.

 

Regards,

Hasham

amitchandak
Super User
Super User

@ReadTheIron , one of the ways it to add measure like

 

countrows(filter(Table, [Date Reported] > [Remediation]))

All measure should follow above filter

 

Or create a column and use that as a visual level filter and filter this column =1

if([Date Reported] > [Remediation] ,1,0)

 

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors