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

Counting matches within a table based on two other columns

Hi All,

 

I have a table of history data (one row per event) that looks like:

PBI Table Search.png

 

The _primarykey here is actually that of a parent table, not the history table... the parent item can have multiple rows in the history table.

 

What I'm looking for is the DAX to populate the "Renewed" column, based on finding another row (for the same parent primary key) that has a 'Start Date' that matches the 'End Date' of the current row.

 

I've tried the following as a calculated column, but i get a syntax error:

 

Renewed =
VAR vkey = history[_primarykey]
VAR vdate = history[End Date]
RETURN
    IF (
        COUNTROWS (
            FILTER (
                FILTER ( FILTER ( history, ALL ), history[_primarykey] = vkey ),
                history[Start Date] = vdate
            )
        )
            > 0,
        "Yes",
        "No"
    )

 

The logic being to expand the table to ALL rows, then filter back down to match the (parent) primary key, and then the dates, and to count the rows of that table... if the count is greater than zero then 'Renewed' = "Yes".

 

All help appreciated.

1 ACCEPTED SOLUTION

@Anonymous

 

This Column should work as well

 

Renewed =
VAR myenddate = Table1[End Date]
RETURN
    IF (
        CONTAINS (
            FILTER ( Table1, Table1[_primarykey] = EARLIER ( Table1[_primarykey] ) ),
            Table1[Start Date], myenddate
        ),
        "Yes",
        "No"
    )

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

Why not just:

 

Renewed Column = IF([EndDate] IN ALL(Matches[StartDate]),"Yes","No")


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...
Anonymous
Not applicable

Hi @Greg_Deckler... well I tried to do it with table filters and counts because I hadn't yet come across the IN operator...

 

The solution suggested doesn't take into account the match on the parent _primarykey also though... I need to match two items between the rows. Does IN handle multiple columns?

OK, try this then:

 

Renewed = IF([EndDate] IN FILTER(ALL(Matches[StartDate]),[_primarykey]=EARLIER([_primarykey])),"Yes","No")


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...

@Anonymous

 

This Column should work as well

 

Renewed =
VAR myenddate = Table1[End Date]
RETURN
    IF (
        CONTAINS (
            FILTER ( Table1, Table1[_primarykey] = EARLIER ( Table1[_primarykey] ) ),
            Table1[Start Date], myenddate
        ),
        "Yes",
        "No"
    )

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