Forum Discussion
Calculating a time duration since a previous timestamp, without calculated columns
- 4 years ago
This calculation will be done for each user separately?
- 4 years ago
Thanks for your response Anonymous . This isn't what I'm looking for.
See the images of my desired result + calculated Column. I want to get to this without any calculated columns, just a measure:The measure I used is simply
Seconds Between Loads = DATEDIFF(MAX(Table1[Last Pallet Loaded]), MAX(Table1[date_time]),SECOND) - 4 years ago
Hi NonprofitWizard
Somehow I missed to answer this query. Aplogies for that.Here is a sample file with the proposed solution https://we.tl/t-Rc90TG1vUz
Measure Tamer = SUMX ( SUMMARIZE ( 'Table', 'Table'[user], 'Table'[pallet_id] ), CALCULATE ( VAR CurrentPallet = SELECTEDVALUE ( 'Table'[pallet_id] ) VAR CurrentUserTable = CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[user] ) ) VAR PreviousPalletsTable = FILTER ( CurrentUserTable, 'Table'[pallet_id] < CurrentPallet ) VAR PreviousPallet = MAXX ( PreviousPalletsTable, 'Table'[pallet_id] ) VAR PreviousPalletRecord = FILTER ( PreviousPalletsTable, 'Table'[pallet_id] = PreviousPallet ) VAR CurrentPalletStart = MIN ( 'Table'[date_time] ) VAR PreviousPalletEnd = MAXX ( PreviousPalletRecord, 'Table'[date_time] ) RETURN DATEDIFF ( PreviousPalletEnd, CurrentPalletStart, SECOND ) ) )
Hi NonprofitWizard ,
Please refer to my pbix file to see if it helps you.
Create a measure.
Measure =
VAR _min =
CALCULATE (
MIN ( 'Table'[date_time] ),
FILTER (
ALL ( 'Table' ),
'Table'[user] = SELECTEDVALUE ( 'Table'[user] )
&& 'Table'[sku] = SELECTEDVALUE ( 'Table'[sku] )
)
)
VAR _next =
CALCULATE (
MAX ( 'Table'[date_time] ),
FILTER (
ALL ( 'Table' ),
'Table'[rankx]
= SELECTEDVALUE ( 'Table'[rankx] ) - 1
&& 'Table'[sku] = SELECTEDVALUE ( 'Table'[sku] )
)
)
VAR _now =
MAX ( 'Table'[date_time] )
RETURN
IF ( MAX ( 'Table'[date_time] ) = _min, 0, DATEDIFF ( _next, _now, SECOND ) )
If I have misunderstood your meaning, please provide y more details with your desired output.
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- NonprofitWizard4 years agoFrequent Visitor
Thanks for your response Anonymous . This isn't what I'm looking for.
See the images of my desired result + calculated Column. I want to get to this without any calculated columns, just a measure:The measure I used is simply
Seconds Between Loads = DATEDIFF(MAX(Table1[Last Pallet Loaded]), MAX(Table1[date_time]),SECOND)- NonprofitWizard4 years agoFrequent Visitor
This wasn't the solution, not sure why it's labeled that way
- tamerj14 years ago
Community Champion
Hi NonprofitWizard
Somehow I missed to answer this query. Aplogies for that.Here is a sample file with the proposed solution https://we.tl/t-Rc90TG1vUz
Measure Tamer = SUMX ( SUMMARIZE ( 'Table', 'Table'[user], 'Table'[pallet_id] ), CALCULATE ( VAR CurrentPallet = SELECTEDVALUE ( 'Table'[pallet_id] ) VAR CurrentUserTable = CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[user] ) ) VAR PreviousPalletsTable = FILTER ( CurrentUserTable, 'Table'[pallet_id] < CurrentPallet ) VAR PreviousPallet = MAXX ( PreviousPalletsTable, 'Table'[pallet_id] ) VAR PreviousPalletRecord = FILTER ( PreviousPalletsTable, 'Table'[pallet_id] = PreviousPallet ) VAR CurrentPalletStart = MIN ( 'Table'[date_time] ) VAR PreviousPalletEnd = MAXX ( PreviousPalletRecord, 'Table'[date_time] ) RETURN DATEDIFF ( PreviousPalletEnd, CurrentPalletStart, SECOND ) ) )