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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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

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

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.