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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Count Records If Record Based on Records in Another Table and Own Table

I have two tables:

Incidents

NumberCreated_At
000007/01/2020
111108/01/2020
222208/05/2020
333308/15/2020

 

Incident Statistics

NumberStatistic_TypeValue
0000to_assignment07/05/2020
1111to_assignment08/01/2020
1111to_resolve08/18/2020
2222to_assignment08/05/2020
2222to_resolve08/25/2020
3333to_assignment08/15/2020

 

I need to show how many 'incidents' where "Open" at the beginning of a period.

 

So, if my slicer was set to look at the period 8/10 - 8/20, I would expect to see 3 Open Incidents. This is because only incident numbers 0000, 1111, 2222 where open on 8/10 (and resolved after 8/10). 

 

** Note: If an incident is still open, it will not have a "to_resolve" record so would still be counted.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

1.Create a calendar table.

Calendar = CALENDAR(DATE(2020,7,1),DATE(2020,8,31))

1.png

 

2.Combine the two tables with Merge in the Power Query Editor and expand the columns.

2.png3.png4.png

 

3.Create a calculated column.

Column = CALCULATE( COUNTROWS('Merge1'),ALLEXCEPT(Merge1,Merge1[Number]))

5.png

 

4.Create a measure to count.

Count = 
VAR count1 =
    CALCULATE (
        COUNTROWS ( 'Merge1' ),
        FILTER ( 'Merge1', [Column] = 1 && MIN ( 'Calendar'[Date] ) >= [Created_At] )
    )
VAR count2 =
    CALCULATE (
        DISTINCTCOUNT ( Merge1[Number] ),
        FILTER (
            'Merge1',
             (
                MIN ( 'Calendar'[Date] ) >= [Created_At]
                    && MIN ( 'Calendar'[Date] ) <= [Value]
                    && [Column] = 2
            )
        )
    )
RETURN
    count1 + count2

 

5.The result is as follows.

6.png

 

You can check more details from here.

 

Best Regards,
Stephen Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

1.Create a calendar table.

Calendar = CALENDAR(DATE(2020,7,1),DATE(2020,8,31))

1.png

 

2.Combine the two tables with Merge in the Power Query Editor and expand the columns.

2.png3.png4.png

 

3.Create a calculated column.

Column = CALCULATE( COUNTROWS('Merge1'),ALLEXCEPT(Merge1,Merge1[Number]))

5.png

 

4.Create a measure to count.

Count = 
VAR count1 =
    CALCULATE (
        COUNTROWS ( 'Merge1' ),
        FILTER ( 'Merge1', [Column] = 1 && MIN ( 'Calendar'[Date] ) >= [Created_At] )
    )
VAR count2 =
    CALCULATE (
        DISTINCTCOUNT ( Merge1[Number] ),
        FILTER (
            'Merge1',
             (
                MIN ( 'Calendar'[Date] ) >= [Created_At]
                    && MIN ( 'Calendar'[Date] ) <= [Value]
                    && [Column] = 2
            )
        )
    )
RETURN
    count1 + count2

 

5.The result is as follows.

6.png

 

You can check more details from here.

 

Best Regards,
Stephen Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@Anonymous - If I understand this correctly, make sure that you have a disconnected slicer and then you could do something like the following:

Measure =
  VAR __MinDate = MIN('Slicer'[Date])
  VAR __Table = 
    ADDCOLUMNS(
      FILTER('Incidents',[Created_At]<=__MinDate),
      "Closed",IF("to resolve" IN SELECTCOLUMNS(RELATEDTABLE('Incident Statistics'),"Closed",[Statistic_Type]),1,0)
    )
RETURN
  COUNTROWS(__Table,[Closed]=0)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
lbendlin
Super User
Super User

Have you tried using LASTNONBLANKVALUE() ?

Anonymous
Not applicable

Hi @lbendlin ,

 

Can you please elaborate on how I would use that function to get a count based on multiple conditions/tables?

 

Thanks!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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