Forum Discussion
Calculation over rows with condition
- Anonymous8 years ago
Hi Anonymous,
If you want to get the summaried stop time you can try to add new measure with below formula:
Stop time(Summaried) = VAR temp = ADDCOLUMNS ( ALL ( Trips ), "Stoped Time", LOOKUPVALUE ( Trips[TripEndDateTime], Trips[VehicleID], [VehicleID], Trips[Date], [Date], Trips[Index], [Index] - 1 ) ) RETURN SUMX ( ADDCOLUMNS ( FILTER ( temp, [VehicleID] = MAX ( [VehicleID] ) && [Date] = MAX ( [Date] ) ), "Diff", DATEDIFF ( [Stoped Time], [TripStartDateTime], SECOND ) ), [Diff] )Regards,
Xiaoxin Sheng
Hi Anonymous,
Based on your description, it sounds like compare current records and previous records.
Can you please share some sample data for further test and analysis?
You can also take a look at below link which has the similar requirement:
Regards,
Xiaoxin Sheng
Anonymous
Sure, here it is:
Sample
- Anonymous8 years agoNot applicable
Hi Anonymous,
Can you please share pbix/excel file with some fake data? I will test on it.(it is trouble to manual input your data from the screenshots)
Regards,
Xiaoxin Sheng
- Anonymous8 years agoNot applicable
Sorry Anonymous, I've been away.
Here is the file.
https://www.dropbox.com/s/wnhwj2ch1r5cfia/Test.pbix?dl=0
Thank you!
- Anonymous8 years agoNot applicable
Hi Anonymous,
You can take a look at below formulas if they suitable for your requirement.
Measures:
Number of Stop = CALCULATE ( COUNT ( [VehicleID] ) - 1, FILTER ( ALLSELECTED ( 'Trips' ), [VehicleID] = MAX ( [VehicleID] ) && [TripStartDate] = MAX ( [TripStartDate] ) && [Date] = MAX ( [Date] ) ) ) Stop time = var _rangeEnd=MAX(Trips[TripStartDateTime]) VAR started = CALCULATE ( MAX ( [TripEndDateTime] ), FILTER ( ALL ( Trips ), [VehicleID] = MAX( [VehicleID] ) && [Date] = MAX ( [Date] ) && [TripEndDateTime] < _rangeEnd ) ) RETURN DATEDIFF ( started,_rangeEnd, SECOND ) + 0 Return time = VAR _lastStart = CALCULATE ( MAX ( Trips[TripStartDateTime] ), FILTER ( ALLSELECTED ( Trips ), [VehicleID] = MAX ( [VehicleID] ) && [Date] = MAX ( Trips[Date] ) ) ) VAR _lastEnd = CALCULATE ( MAX ( Trips[TripEndDateTime] ), FILTER ( ALLSELECTED ( Trips ), [VehicleID] = MAX ( [VehicleID] ) && [Date] = MAX ( Trips[Date] ) ) ) RETURN IF ( DATEVALUE ( _lastStart ) <> DATEVALUE ( _lastEnd ), DATEDIFF ( _lastStart, _lastEnd, SECOND ), DATEDIFF ( _lastEnd, DATEVALUE ( _lastEnd ) + 1, SECOND ) )Regards,
Xiaoxin Sheng