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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Blizzardstyx
Frequent Visitor

Count of dates in another column

Hi all,

 

Need help with calculating number of times that a date shows up in another date column. I also need it to be filtered for a specific tractor ID

 

The two columns are [Pickup date] and [return date] and all I need to do is figure out how many times that a specific return date is found in the [Pickup date] column. It might just be an earlier function, but I just can't seem to get it right.

 

Here's an example table

Tractor IDActivity IDPickup DateReturn DateCount** (column I need)
511.1.20201.12.20202
521.12.20201.12.20202
531.12.20201.30.20200
1041.30.20201.30.20201
1051.31.20202.5.20200
1061.31.20201.31.20202

 

I have an example file here for people to work out of:

https://drive.google.com/file/d/1kDeDBJzJK2NXXWbV9uYqJs_TzRVjs1qd/view?usp=sharing

 

Thanks in advance!

 

Thank you in advance

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Blizzardstyx 

 

Based on your description, I created data to reproduce your scenario.

Table:

a1.png

 

You may create a measure as follows.

 

Count = 
var _tractorid = MAX('Table'[Tractor ID])
var _returndate = MAX('Table'[Return Date])
var _count = 
COUNTROWS(
    FILTER(
        ALLSELECTED('Table'),
        'Table'[Tractor ID] = _tractorid&&
        'Table'[Pickup Date] = _returndate
    )
)

return
IF(
    ISBLANK(_count),
    0,
    _count
)

 

 

Result:

a2.png

 

Best Regards

Allan

 

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

6 REPLIES 6
v-alq-msft
Community Support
Community Support

Hi, @Blizzardstyx 

 

Based on your description, I created data to reproduce your scenario.

Table:

a1.png

 

You may create a measure as follows.

 

Count = 
var _tractorid = MAX('Table'[Tractor ID])
var _returndate = MAX('Table'[Return Date])
var _count = 
COUNTROWS(
    FILTER(
        ALLSELECTED('Table'),
        'Table'[Tractor ID] = _tractorid&&
        'Table'[Pickup Date] = _returndate
    )
)

return
IF(
    ISBLANK(_count),
    0,
    _count
)

 

 

Result:

a2.png

 

Best Regards

Allan

 

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

Anonymous
Not applicable

Hey @Blizzardstyx 

 

I'm not sure I'm understanding. You're wanting to know how many times there were returns on a pickup date or how many items on a specific pickup date were returned later?

Hi @Anonymous ,

 

Just modified the question above. Hope it makes more sense.

 

Thank you!

Anonymous
Not applicable

Ah. I see now. That is simple. You just need the countx function:

 

https://docs.microsoft.com/en-us/dax/countx-function-dax

 

Try Count = COUNTX(Table[Pickup Date], Table[Return Date])

 

set it up as a calculated column and change the "Table" in the formula. Let me know if it works.

 

If this helps please Kudo. 

If this solves your problem please accept it as a solution.

I don't believe I can put 'Table[Pickup Date]' as the first argument of a countx formula. It asks for a table, not column.

Anonymous
Not applicable

Hey @Blizzardstyx 

 

You are correct. You will need to create a duplicate table (aka a reference query), remove the other columns, then remove duplicate rows, and create the measure so that your pickup date and return are in separate tables.

 

You can also do it in query editor as shown in the sample file in this thread: https://community.powerbi.com/t5/Desktop/Count-If-from-the-same-table/td-p/531223

 

or this one: https://community.powerbi.com/t5/Desktop/COUNTIF-in-Query-Editor/td-p/657700

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