Forum Discussion
Difference between dates on different rows and same column AFTER filtering
- 3 years ago
hi leodm
try to add plot all the columns with a measure like:
Result = VAR _date = MAX(TableName[Date]) VAR _datepre = MAXX( FILTER( ALLSELECTED(TableName), TableName[Date]<_date ), TableName[Date] ) VAR _Difference= _date - _datepre VAR _Days = INT(_Difference) VAR _Hours = HOUR(_Difference) VAR _Minutes = MINUTE(_Difference) VAR _Seconds = SECOND(_Difference) VAR _DaysToHours = _Days * 24 VAR _TotalHours = _DaysToHours + _Hours RETURN IF( _datepre<>BLANK(), FORMAT(_TotalHours, "00") & ":" & FORMAT(_Minutes, "00") & ":" & FORMAT(_Seconds,"00"), " " )it worked like:
leodm Hi!
Yes, you are correct. In order to calculate the time difference dynamically based on the filters, you will need to use a measure instead of a calculated column. Here's an example of how you can create a measure to calculate the time difference:
-
Open the Power BI desktop and select the table that contains the date and time values you want to calculate the time difference for.
-
Click on the "New measure" button in the "Modeling" tab.
-
In the formula bar, enter the following DAX formula:
Time Difference =
IF (
SELECTEDVALUE ( 'Table'[Squad] ) = BLANK () ||
SELECTEDVALUE ( 'Table'[Art] ) = BLANK (),
BLANK (),
CALCULATE (
SUM ( 'Table'[Data de início real] ) - MIN ( 'Table'[Data de início real] ),
ALLEXCEPT ( 'Table', 'Table'[Squad], 'Table'[Art] )
)
)
-
Add the measure to a visual to see the time difference between the selected Squad and Art values dynamically update based on the filters applied.
BBF