Forum Discussion
Difference in Meter Reading Calculation based on dates
- Anonymous1 year ago
Hi harshagraj ,
I updated the formula of measure in the attached pbix file, please check if that is what you want.
Difference = VAR _shifttype = SELECTEDVALUE ( 'Table'[ShiftStartOrEnd] ) VAR _date = SELECTEDVALUE ( 'Table'[ReadingCaptureOn] ) VAR _shift = SELECTEDVALUE ( 'Table'[Shift Name] ) VAR _input = SELECTEDVALUE ( 'Table'[Input] ) VAR _ss1 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( 'Table', 'Table'[Shift Name] = "Shift 1"&&'Table'[Input]=_input&&'Table'[ReadingCaptureOn]=_date ) ) VAR _ss2 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED('Table'), 'Table'[Shift Name] = "Shift 2"&&'Table'[Input]=_input&&'Table'[ReadingCaptureOn]=_date ) ) VAR _ss3 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED('Table'), 'Table'[Shift Name] = "Shift 3" &&'Table'[Input]=_input&&'Table'[ReadingCaptureOn]=_date ) ) VAR _es1 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Shift Name] = "Shift 1" && 'Table'[Input] = _input && 'Table'[ReadingCaptureOn] = _date + 1 ) ) VAR _es2 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Shift Name] = "Shift 2" && 'Table'[Input] = _input && 'Table'[ReadingCaptureOn] = _date + 1 ) ) VAR _es3 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Shift Name] = "Shift 3" && 'Table'[Input] = _input && 'Table'[ReadingCaptureOn] = _date + 1 ) ) RETURN SWITCH ( TRUE (), _shifttype = "Start" && _shift = "Shift 1", _ss1 - _ss2, _shifttype = "Start" && _shift = "Shift 2", _ss2 - _ss3, _shifttype = "Start" && _shift = "Shift 3", _ss3 - _es1, _shifttype = "End" && _shift = "Shift 1", _ss3 - _es1, _shifttype = "End" && _shift = "Shift 2", _es1 - _es2, _shifttype = "End" && _shift = "Shift 3", _es2 - _es3 )Best Regards
Hi harshagraj ,
I created a sample pbix file(see the attachment), please check if that is what you want.
Difference =
VAR _shifttype =
SELECTEDVALUE ( 'Table'[ShiftStartOrEnd] )
VAR _date =
SELECTEDVALUE ( 'Table'[ReadingCaptureOn] )
VAR _shift =
SELECTEDVALUE ( 'Table'[Shift Name] )
VAR _input =
SELECTEDVALUE ( 'Table'[Input] )
VAR _ss1 =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER ( 'Table', 'Table'[Shift Name] = "Shift 1" )
)
VAR _ss2 =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER ( 'Table', 'Table'[Shift Name] = "Shift 2" )
)
VAR _ss3 =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER ( 'Table', 'Table'[Shift Name] = "Shift 3" )
)
VAR _es1 =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Shift Name] = "Shift 1"
&& 'Table'[Input] = _input
&& 'Table'[ReadingCaptureOn] = _date + 1
)
)
VAR _es2 =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Shift Name] = "Shift 2"
&& 'Table'[Input] = _input
&& 'Table'[ReadingCaptureOn] = _date + 1
)
)
VAR _es3 =
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Shift Name] = "Shift 3"
&& 'Table'[Input] = _input
&& 'Table'[ReadingCaptureOn] = _date + 1
)
)
RETURN
SWITCH (
TRUE (),
_shifttype = "Start"
&& _shift = "Shift 1", _ss1 - _ss2,
_shifttype = "Start"
&& _shift = "Shift 2", _ss2 - _ss3,
_shifttype = "Start"
&& _shift = "Shift 3", _ss3 - _es1,
_shifttype = "End"
&& _shift = "Shift 1", _ss3 - _es1,
_shifttype = "End"
&& _shift = "Shift 2", _es1 - _es2,
_shifttype = "End"
&& _shift = "Shift 3", _es2 - _es3
)
Best Regards
Hello Anonymous thanks a lot for your inputs. In the below screenshot i have selected Start so for 07/29/2024 it should be Shift1 -Shift 2 >>2943326-5415093 = - 2,471,767 as Shift 1 and Shift 2- Shift 3 = 5415093-2683621 as Shift 2 and Shift 3 - Shift 1(07/30/2024) = 2683621-1206540.
But I am seeing different values. Could you help me?
Also for end it should calculate differnce as Shift3(July 29,2024)-Shift1(July 30,2024) at Shift1 (July 30,2024), Shift1(July 30,2024)-Shift2(July 30,2024) at Shift2 (July 30,2024) and Shift2(July 30,2024)-Shift3(July 30,2024) at Shift 3(July 30,2024)
Also if i remove Sum of value from the context the difference should still work. I need this to put on bar charts. Thanks in advance
- Anonymous1 year agoNot applicable
Hi harshagraj ,
I updated the formula of measure in the attached pbix file, please check if that is what you want.
Difference = VAR _shifttype = SELECTEDVALUE ( 'Table'[ShiftStartOrEnd] ) VAR _date = SELECTEDVALUE ( 'Table'[ReadingCaptureOn] ) VAR _shift = SELECTEDVALUE ( 'Table'[Shift Name] ) VAR _input = SELECTEDVALUE ( 'Table'[Input] ) VAR _ss1 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( 'Table', 'Table'[Shift Name] = "Shift 1"&&'Table'[Input]=_input&&'Table'[ReadingCaptureOn]=_date ) ) VAR _ss2 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED('Table'), 'Table'[Shift Name] = "Shift 2"&&'Table'[Input]=_input&&'Table'[ReadingCaptureOn]=_date ) ) VAR _ss3 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED('Table'), 'Table'[Shift Name] = "Shift 3" &&'Table'[Input]=_input&&'Table'[ReadingCaptureOn]=_date ) ) VAR _es1 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Shift Name] = "Shift 1" && 'Table'[Input] = _input && 'Table'[ReadingCaptureOn] = _date + 1 ) ) VAR _es2 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Shift Name] = "Shift 2" && 'Table'[Input] = _input && 'Table'[ReadingCaptureOn] = _date + 1 ) ) VAR _es3 = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Shift Name] = "Shift 3" && 'Table'[Input] = _input && 'Table'[ReadingCaptureOn] = _date + 1 ) ) RETURN SWITCH ( TRUE (), _shifttype = "Start" && _shift = "Shift 1", _ss1 - _ss2, _shifttype = "Start" && _shift = "Shift 2", _ss2 - _ss3, _shifttype = "Start" && _shift = "Shift 3", _ss3 - _es1, _shifttype = "End" && _shift = "Shift 1", _ss3 - _es1, _shifttype = "End" && _shift = "Shift 2", _es1 - _es2, _shifttype = "End" && _shift = "Shift 3", _es2 - _es3 )Best Regards
- harshagraj1 year agoPost Partisan
Hi Anonymous thanks a lot. This is working
- harshagraj1 year agoPost Partisan
Hello Anonymous sorry that this is working only for a matrix when all those columns are available. But if i have to make some card visual out of it its becoming blank or an column chart.
- harshagraj1 year agoPost Partisan
Hello Anonymous waiting for your response.