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

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

Reply
ReadTheIron
Helper III
Helper III

Filtering a table on multiple criteria

I have two related tables, AssetTable and IncidentTable. I am trying to get a count of entries in FailureTable that satisfy multiple criteria. Specifically, I want to create a calculated column to count entries after a given date and excluding a given cause. Here, I want to count every incident except snow incidents after the asset was repaired.

 

Data examples:

AssetTable

AssetRepairDate
Switch12/2/2022
Switch22/3/2022
Switch32/4/2022

 

IncidentTable

AssetIncidentDateCause
Switch11/1/2022Snow
Switch11/12/2022Wind
Switch22/4/2022Fog
Switch12/4/2022Fog
Switch32/15/2022Snow
Switch12/20/2022Snow
Switch12/25/2022Wind

 

Desired table

AssetDate RepairedQualifyingIncidentsAfterRepair
Switch12/2/20222
Switch22/3/20221
Switch32/4/20220

 

My current calculated column only counts the incidents after the repair.

 

IncidentsAfterRepair =
IF(ISBLANK('AssetTable'[RepairDate]),0,
COUNTX(
    FILTER(
        RELATEDTABLE(IncidentTable),'AssetTable'[RepairDate]<=IncidentTable[IncidentDate]),IncidentTable[IncidentDate])+0)
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula will work

=coalesce(CALCULATE(COUNTROWS(Incident),FILTER(Incident,Incident[Asset]=EARLIER(Asset[Asset])&&Incident[IncidentDate]>EARLIER(Asset[RepairDate])&&Incident[Cause]<>"snow")),0)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula will work

=coalesce(CALCULATE(COUNTROWS(Incident),FILTER(Incident,Incident[Asset]=EARLIER(Asset[Asset])&&Incident[IncidentDate]>EARLIER(Asset[RepairDate])&&Incident[Cause]<>"snow")),0)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I'm writing this column for other asset tables, which I believe are formatted exactly the same way, but I'm getting "The first argument of EARLIER/EARLIEST is not a valid column reference in the earlier row context". I can't figure out why it would work on one and not the other. Any thoughts?

Never mind, found my error - the AssetRepairDate being referred to was a measure not a column. Changed it from a measure to a calculated column and now everything is working.

Thank you! This worked beautifully!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

You were close.

IncidentsAfterRepair = 
IF(ISBLANK([RepairDate]),0,
COUNTX(FILTER(RELATEDTABLE(IncidentTable),[RepairDate]<=[IncidentDate] && [Cause]<>"Snow" ),1)+0)

 

Are you sure you want this as a calculated column though?

I'm getting "too many arguments passed to the FILTER function. The maximum argument count for the function is 2"

 

I will eventually want to use totals from this, so I was looking for a column instead of a measure - if a measure would make more sense, I can give that a try.

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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