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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

DateDiff in Measures

I have the following 3 measures in the Application User Table. This is connected to the AccessLog table via user id.

 

1stToLastLogin = CALCULATE(

MAXX ( TOPN ( 1, 'AccessLog', 'AccessLog'[AccessDate] ), 'AccessLog'[AccessDate]),

FILTER('Date','Date'[DateId]=SELECTEDVALUE('DateSelector'[DateId],MAX('DateSelector'[DateId]))))+0


2ndToLastLogin = CALCULATE(

MINX ( TOPN ( 1, 'AccessLog', 'AccessLog'[AccessDate] ), 'AccessLog'[AccessDate]),

FILTER('Date','Date'[DateId]<=SELECTEDVALUE('DateSelector'[DateId],MAX('DateSelector'[DateId]))))+0


RepeatTimeToAccess = DATEDIFF([2ndToLastLogin],[1stToLastLogin],SECOND)

On a power bi page I have a selected single date like the 25/02/2020 say.


So I get values similar to below : ( No real data is being shared here just sample data)

 

Appuser 1stToLastLogin 2ndToLastLogin RepeatTimeToAccess

2 25/02/2020 05:09:42 25/02/2020 05:09:32 10
2 25/02/2020 05:09:40 25/02/2020 05:09:38 2
TOTAL 25/02/2020 23:59:48 25/02/2020 23:59:47 1 --- ?

 

However the total for RepeatTimetoAccess is wrong . It does not add each individual row to give a grand total . It recalcualtes the total based on a max of 1stToLastLogin - a max of 2ndToLastLogin to give a completed nonsence high level figure .

 

I cannot use calculated columns as I am using direct query and the restrictions around max and min , and I understand datediff does not really have the sum x and other x aggregration functionality. What is the simplest way round this to give me a proper total RepeatTimeToAccess figure ?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Row context is very important. Please refer to my blog: https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

Row context is very important. Please refer to my blog: https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.