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
Dunner2020
Post Prodigy
Post Prodigy

Counting no of rows when difference between two dates are in certain range

Hi there,

 

I want to write a measure that counts the number of cancelled events when the difference between the cancelled date of the event and the actual start date of event is less than 24 hours. I have some data inclusion filters that are applied at the page level. I want the measure to calculate the cancelled event on inclusion data only. The date data looks like as follow:

leo_89_0-1606688632033.png

Cancelled Date has a default value of '1/01/1900 1:00:00 pm' which means no cancellation date. I wanted to calculate the no of events that have cancelled date. So my measure is as follow:

 

Cancellation events =

var cancel_date = MAX('Table'[Cancelled Date ])
Var actual_date = MAX('Table'[Actual Interruption Start Time])
 
RETURN
COUNTROWS(FILTER('Table', IF(YEAR(cancel_date)>1900,DATEDIFF(cancel_date,actual_date,HOUR)) < 24))
 
However, the above result did not produce the desired result. It shows blank value when I tried to display on the card visual. I am not sure whether I am calculating in the right manner or not. Any help would be really appreciated.

Data can be download from here 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Dunner2020 , Create a measure like

calculate(countrows(Table), filter( Table, datediff(Table[Cancelled Date ],Table[Actual Interruption Start Time],hour)<24))

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

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Dunner2020 , Create a measure like

calculate(countrows(Table), filter( Table, datediff(Table[Cancelled Date ],Table[Actual Interruption Start Time],hour)<24))

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

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