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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
v_mark
Helper V
Helper V

Count of Tickets in X amount of hours

I was trying to create a Card Visual each that has the following condition
Less than 24hrs, More than 72hrs, and more than 120hrs Total tickets created 

Eventually, I will be needing to put it on a matrix

 

I was wondering how can I write a DAX measure that I can use for each card? 

 

I have two tables 

 

Fact table that has CreatedDateTime and Ticket IDs
with *:1 relationship to

Dim_Date table 

1 ACCEPTED SOLUTION

Hi @v_mark 

I create a sample to have a test.

1.png

Firstly, create a calculated table for slicer.

Slicer = {"Less than 24hrs", "More than 72hrs", "More than 120hrs"}

Measure:

Measure = 
VAR _SelectValue = SELECTEDVALUE(Slicer[Value])
VAR _LESS24hrs = CALCULATE(COUNT('Table'[Ticket IDs]),FILTER(ALL('Table'),DATEDIFF('Table'[CreatedDateTime],NOW(),HOUR)<24))
VAR _More72hrs = CALCULATE(COUNT('Table'[Ticket IDs]),FILTER(ALL('Table'),DATEDIFF('Table'[CreatedDateTime],NOW(),HOUR)>72))
VAR _More120hrs = CALCULATE(COUNT('Table'[Ticket IDs]),FILTER(ALL('Table'),DATEDIFF('Table'[CreatedDateTime],NOW(),HOUR)>120))
RETURN
SWITCH(_SelectValue,"Less than 24hrs",_LESS24hrs,"More than 72hrs",_More72hrs, "More than 120hrs",_More120hrs)

Result is as below.

1.png

Select More than 120hrs:

2.png

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
v_mark
Helper V
Helper V

@VahidDM - I appreciate the response. So far there is no requirement about business hours and weekends.

I might look for a way to use DATEDIFF in a measure instead of a calculated column.  OR 

perhaps do the calculation back in PQ

Hi @v_mark 

I create a sample to have a test.

1.png

Firstly, create a calculated table for slicer.

Slicer = {"Less than 24hrs", "More than 72hrs", "More than 120hrs"}

Measure:

Measure = 
VAR _SelectValue = SELECTEDVALUE(Slicer[Value])
VAR _LESS24hrs = CALCULATE(COUNT('Table'[Ticket IDs]),FILTER(ALL('Table'),DATEDIFF('Table'[CreatedDateTime],NOW(),HOUR)<24))
VAR _More72hrs = CALCULATE(COUNT('Table'[Ticket IDs]),FILTER(ALL('Table'),DATEDIFF('Table'[CreatedDateTime],NOW(),HOUR)>72))
VAR _More120hrs = CALCULATE(COUNT('Table'[Ticket IDs]),FILTER(ALL('Table'),DATEDIFF('Table'[CreatedDateTime],NOW(),HOUR)>120))
RETURN
SWITCH(_SelectValue,"Less than 24hrs",_LESS24hrs,"More than 72hrs",_More72hrs, "More than 120hrs",_More120hrs)

Result is as below.

1.png

Select More than 120hrs:

2.png

Best Regards,
Rico Zhou

 

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

VahidDM
Super User
Super User

Hi @v_mark 

 

It seems you need to calculate the Business Hours between CreatedDateTime and Now.

You can use the business hours calculation dax formula:

https://www.vahiddm.com/post/calculating-business-hours-in-power-bi-using-dax

or if the business hour and weekend are not important, you can use DATEDIFF dax code and set that to calculate Hour.

 

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

Appreciate your Kudos!!

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.