cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
shreyaashok Visitor
Visitor

DAX relative time function to count number of instances between specific times

Hi, 

 

I have some data in the following format: 

 

Incident Number Date Occurred Incident Name 
1431/1/2001 12:00ex 1
3611/2/2001 14:00ex 2

 

I am trying to count the number of incidents that have a [Date Occurred] within a certain time frame relative to the current date. I want the number of incidents with a [Date Occurred] between 7 days ago after 12:00 PM to today before 12:00 PM. 

 

To give an example: if it is Thursday today, I would like to count the number of incidents with a [Date Occurred] between LAST thursday after 12:00 PM and 12:00 PM this Thursday (today). 

 

Ideally, I would like a measure to get this count. 

 

Thanks!

2 REPLIES 2
Super User
Super User

Re: DAX relative time function to count number of instances between specific times

Hi @shreyaashok 

Try this measure in a card visual:

 

Measure =
VAR Today12_ =
    TODAY () + ( 12 / 24 ) //Add 12 hours
VAR Beginning_ = Today12_ - 7 // Subtract 7 days
RETURN
    CALCULATE (
        COUNTROWS ( Table1 ),
        Table1[Date Occurred] >= Beginning_,
        Table1[Date Occurred] < Today12_
    )

 

 

Super User
Super User

Re: DAX relative time function to count number of instances between specific times

I think you should have 2 columns, which would probably make this problem easier and secondly, it's best practice anyway: one column should store the date part and another should store the time part.

Then it would be much easier to move through dates without having to fiddle with time.

Best
Darek

Helpful resources

Announcements
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Power BI Helps Homeless and Trouble Youth

Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 78 members 1,218 guests
Please welcome our newest community members: