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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
jitpbi
Post Patron
Post Patron

calculate count for last 1 hour from latest datetime

Hi,

 

I need to display the count of fault types for last 1 hour from the maximum datetime from the below dataset:

 

jitpbi_0-1613753439295.png

 

i tried with the below dax but it is giving incorrect value:

 

jitpbi_1-1613753742601.png

 

In the below screenshot, the highlighted fault count should not be displayed if we refer the last 1 hour fault type from the table where MOGAlarm is the only fault type the why Healthy is coming:

 

jitpbi_1-1613754732646.png

 

 

Please suggest how to do it correctly.

 

Thanks

 

 

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

Don't @jitpbi,

By my understanding, you want to count all the categories when their time comes an hour ago, right?

You can use the following formula:

Measure =
VAR _max =
    MAXX ( ALL ( 'Table' ), 'Table'[Time] )
RETURN
    CALCULATE (
        COUNT ( 'Table'[Cate] ),
        FILTER ( 'Table', DATEDIFF ( 'Table'[Time], _max, SECOND ) <= 3600 )
    )

The final output is shown below:

2.22.5.1.PNG

Please take a look at the pbix file here.

Best regards
Qin eyelids
If this post helps, consider ACCEPT as the solution to help other members find it faster.

View solution in original post

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Don't @jitpbi,

By my understanding, you want to count all the categories when their time comes an hour ago, right?

You can use the following formula:

Measure =
VAR _max =
    MAXX ( ALL ( 'Table' ), 'Table'[Time] )
RETURN
    CALCULATE (
        COUNT ( 'Table'[Cate] ),
        FILTER ( 'Table', DATEDIFF ( 'Table'[Time], _max, SECOND ) <= 3600 )
    )

The final output is shown below:

2.22.5.1.PNG

Please take a look at the pbix file here.

Best regards
Qin eyelids
If this post helps, consider ACCEPT as the solution to help other members find it faster.

Shishir22
Solution Sage
Solution Sage

Hello @jitpbi ,

 

I would suggest divide datetime into 2 calculated columns one with date and one with time.

 

Date = FORMAT(Fault[DateTime].[Date],"dd/mm/yyyy")

 

Time = FORMAT(Fault[DateTime],"hh:mm:ss")

 

Please give datatype as date and time respectively.

 

Create measure for count as :

 

FaultTypeCount = 
COUNTX(FILTER(Fault,Fault[Date]=MAX(Fault[Date]) && Fault[Time]>=(MAX(Fault[Time])-1/24)),Fault[Fault_type])

 

Shishir22_0-1613763892167.png

 

If it fulfils your requirement, please mark it as solution.

 

Thanks!

 

 

 

 

Cheers,
Shishir

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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