Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi everyone,
I'm trying to make a Dax code that gives me a count of events but if there in the timestamp between them is less than 2 minutes that this counts as 1 event.
For example:
| Event | date | time |
| A | 1-1-2024 | 8:00:00 |
| A | 1-1-2024 | 8:00:42 |
| B | 1-1-2024 | 8:01:32 |
| A | 1-1-2024 | 8:01:58 |
| B | 1-1-2024 | 8:02:00 |
| A | 1-1-2024 | 8:07:00 |
| B | 1-1-2024 | 8:08:52 |
| A | 1-1-2024 | 8:21:00 |
| B | 1-1-2024 | 8:35:00 |
| B | 1-1-2024 | 8:35:58 |
Needed results:
Event A: 3
Event B; 3
Thnx for the support.
Solved! Go to Solution.
I assume you mean that if the diffrence between the two consecutive times for an event is less than 2 minutes then it should be considered as single record
For example difference between 00:00 and 00:42 is less than 2 minutes and so is the difference between 00:42 and 01:58 less than 2 minutes , so both should be considered as a one count.difference between 01:58 and 07:00 is greater than 2 so it should be considered one new count.
Create a measure. t is the table name
TimeDifference =
VAR _M =
DATEDIFF (
CALCULATE (
MAX ( t[time] ),
OFFSET (
-1,
( ALL ( t ) ),
ORDERBY ( t[date].[Date], DESC ),
,
PARTITIONBY ( t[Event] ),
MATCHBY ( t[date].[Date], t[time] )
)
),
MAX( t[time] ),
MINUTE
)
RETURN
IF ( _M < 2, 0, _M )
Then create a table
Table = SUMMARIZE(t,t[Event],t[date],t[time],"TimeDifference",[TimeDifference])
and create a new measure in the table to get the distinct count
FinalCount = DISTINCTCOUNT('Table'[TimeDifference])
I assume you mean that if the diffrence between the two consecutive times for an event is less than 2 minutes then it should be considered as single record
For example difference between 00:00 and 00:42 is less than 2 minutes and so is the difference between 00:42 and 01:58 less than 2 minutes , so both should be considered as a one count.difference between 01:58 and 07:00 is greater than 2 so it should be considered one new count.
Create a measure. t is the table name
TimeDifference =
VAR _M =
DATEDIFF (
CALCULATE (
MAX ( t[time] ),
OFFSET (
-1,
( ALL ( t ) ),
ORDERBY ( t[date].[Date], DESC ),
,
PARTITIONBY ( t[Event] ),
MATCHBY ( t[date].[Date], t[time] )
)
),
MAX( t[time] ),
MINUTE
)
RETURN
IF ( _M < 2, 0, _M )
Then create a table
Table = SUMMARIZE(t,t[Event],t[date],t[time],"TimeDifference",[TimeDifference])
and create a new measure in the table to get the distinct count
FinalCount = DISTINCTCOUNT('Table'[TimeDifference])
In the dax i get an error on:
I want to know the error message. After you create the measure it should give you an error message.
The column reference to Date in the SQL Logdata table cannot be used for the date variant because it does not contain a variant.
I suspect it has to do with the data type of the column. Can you share the PBI file with some mock data ?
How can i share a PBI?
Also check this post.It has some great insights.
https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Column-reference-to-Date-in-table-ca...
Hi,
Here is one way to do this with dax:
You can visualize this in dax query view:
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/
Proud to be a Super User!
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 4 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 17 | |
| 8 | |
| 8 | |
| 7 |