Forum Discussion

harshagraj's avatar
harshagraj
Post Partisan
1 year ago
Solved

Difference in Meter Reading Calculation based on dates

Hello all,

Based on the below image i need some assistance either to structure the data or a calculation.

If I select the Start then considering July 29, 2024 it should calculate differnce as Shift1-Shift2 at Shift1, Shift2-Shift3 at Shift2 and Shift3-Shift1(July 30,2024) at Shift 3 (July 29,2024) 
If I select the End then considering July 29, 2024 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)


Please guide me how to solve this.Attaching sample data.

User IDUser NameReadingCaptureOnShift NameShiftStartOrEndInputValue
174913Jon7/28/2024Shift 3StartP12244567
174913Jon7/28/2024Shift 3StartP32344567
174913Jon7/28/2024Shift 3StartP21962234
175833Bart7/29/2024Shift 1StartP12943326
175833Bart7/29/2024Shift 1StartP32989733
175833Bart7/29/2024Shift 1StartP23042042
175833Bart7/29/2024Shift 2EndP12281906
175833Bart7/29/2024Shift 2EndP32823592
175833Bart7/29/2024Shift 2EndP22969746
174913Jon7/29/2024Shift 2StartP12782375
174913Jon7/29/2024Shift 2StartP32982522
174913Jon7/29/2024Shift 2StartP23020714
174913Jon7/29/2024Shift 2EndP12802801
174913Jon7/29/2024Shift 2EndP32605439
174913Jon7/29/2024Shift 2EndP22906316
174557Wan7/29/2024Shift 2StartP12632718
174557Wan7/29/2024Shift 2StartP32272392
174557Wan7/29/2024Shift 2StartP22941521
174557Wan7/29/2024Shift 3StartP12683621
174557Wan7/29/2024Shift 3StartP32982543
174557Wan7/29/2024Shift 3StartP22894587
174557Wan7/30/2024Shift 3EndP11335543
174557Wan7/30/2024Shift 3EndP31160300
174557Wan7/30/2024Shift 3EndP23326923
175833Bart7/30/2024Shift 1StartP11206540
175833Bart7/30/2024Shift 1StartP31050958
175833Bart7/30/2024Shift 1StartP23326974
175833Bart7/30/2024Shift 1EndP11242837
175833Bart7/30/2024Shift 1EndP31081205
175833Bart7/30/2024Shift 1EndP23326924
174913Jon7/30/2024Shift 2StartP11242837
174913Jon7/30/2024Shift 2StartP31081205
174913Jon7/30/2024Shift 2StartP23326924
174557Wan7/30/2024Shift 3StartP11282022
174557Wan7/30/2024Shift 3StartP31115002
174557Wan7/30/2024Shift 3StartP23326924
174913Jon7/30/2024Shift 3EndP11282022
174913Jon7/30/2024Shift 3EndP31115002
174913Jon7/30/2024Shift 3EndP23326924
174913Jon7/30/2024Shift 2EndP11282022
174913Jon7/30/2024Shift 2EndP31115002
174913Jon7/30/2024Shift 2EndP23326924
175833Bart7/31/2024Shift 1StartP11335543
175833Bart7/31/2024Shift 1StartP31160300
175833Bart7/31/2024Shift 1StartP23326924
175833Bart7/31/2024Shift 1EndP11367492
175833Bart7/31/2024Shift 1EndP31186612
175833Bart7/31/2024Shift 1EndP23329164
174913Jon7/31/2024Shift 2StartP11367492
174913Jon7/31/2024Shift 2StartP31186612
174913Jon7/31/2024Shift 2StartP23329164
175422Peter7/31/2024Shift 3StartP11374583
175422Peter7/31/2024Shift 3StartP31194139
175422Peter7/31/2024Shift 3StartP23351105
174913Jon7/31/2024Shift 2EndP11374583
174913Jon7/31/2024Shift 2EndP31194139
174913Jon7/31/2024Shift 2EndP23351105
175422Peter7/31/2024Shift 3EndP11423881
175422Peter7/31/2024Shift 3EndP31234736
175422Peter7/31/2024Shift 3EndP23351105

 

amitchandak VijayPerepa 

  • Anonymous's avatar
    Anonymous
    1 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

8 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    harshagraj I don't see a Shift 3 End on 7/29/2024. So are you supposed to use the Start for Shift 3 when End is selected? A bit confused.

    "If I select the End then considering July 29, 2024 it should calculate differnce as Shift3(July 29,2024)-Shift1(July 30,2024) at Shift1 (July 30,2024)"

    • harshagraj's avatar
      harshagraj
      Post Partisan

      Hello Greg_Deckler thanks a lot for the reply. Actually this is a sample dataset. Technically speaking Shift1 end will be as same as Shift 2 Start and so on. I am correcting the data.

      User IDUser NameReadingCaptureOnShift NameShiftStartOrEndInputValue
      174913Jon7/28/2024Shift 3StartP12244567
      174913Jon7/28/2024Shift 3StartP32344567
      174913Jon7/28/2024Shift 3StartP21962234
      175833Bart7/29/2024Shift 1StartP12943326
      175833Bart7/29/2024Shift 1StartP32989733
      175833Bart7/29/2024Shift 1StartP23042042
      175833Bart7/29/2024Shift 2EndP12281906
      175833Bart7/29/2024Shift 2EndP32823592
      175833Bart7/29/2024Shift 2EndP22969746
      174913Jon7/29/2024Shift 2StartP12782375
      174913Jon7/29/2024Shift 2StartP32982522
      174913Jon7/29/2024Shift 2StartP23020714
      174913Jon7/29/2024Shift 2EndP12802801
      174913Jon7/29/2024Shift 2EndP32605439
      174913Jon7/29/2024Shift 2EndP22906316
      174557Wan7/29/2024Shift 2StartP12632718
      174557Wan7/29/2024Shift 2StartP32272392
      174557Wan7/29/2024Shift 2StartP22941521
      174557Wan7/29/2024Shift 3StartP12683621
      174557Wan7/29/2024Shift 3StartP32982543
      174557Wan7/29/2024Shift 3StartP22894587
      174557Wan7/30/2024Shift 3EndP11335543
      174557Wan7/30/2024Shift 3EndP31160300
      174557Wan7/30/2024Shift 3EndP23326923
      175833Bart7/30/2024Shift 1StartP11206540
      175833Bart7/30/2024Shift 1StartP31050958
      175833Bart7/30/2024Shift 1StartP23326974
      175833Bart7/30/2024Shift 1EndP11242837
      175833Bart7/30/2024Shift 1EndP31081205
      175833Bart7/30/2024Shift 1EndP23326924
      174913Jon7/30/2024Shift 2StartP11242837
      174913Jon7/30/2024Shift 2StartP31081205
      174913Jon7/30/2024Shift 2StartP23326924
      174557Wan7/30/2024Shift 3StartP11282022
      174557Wan7/30/2024Shift 3StartP31115002
      174557Wan7/30/2024Shift 3StartP23326924
      174913Jon7/30/2024Shift 3EndP11282022
      174913Jon7/30/2024Shift 3EndP31115002
      174913Jon7/30/2024Shift 3EndP23326924
      174913Jon7/30/2024Shift 2EndP11282022
      174913Jon7/30/2024Shift 2EndP31115002
      174913Jon7/30/2024Shift 2EndP23326924
      175833Bart7/31/2024Shift 1StartP11335543
      175833Bart7/31/2024Shift 1StartP31160300
      175833Bart7/31/2024Shift 1StartP23326924
      175833Bart7/31/2024Shift 1EndP11367492
      175833Bart7/31/2024Shift 1EndP31186612
      175833Bart7/31/2024Shift 1EndP23329164
      174913Jon7/31/2024Shift 2StartP11367492
      174913Jon7/31/2024Shift 2StartP31186612
      174913Jon7/31/2024Shift 2StartP23329164
      175422Peter7/31/2024Shift 3StartP11374583
      175422Peter7/31/2024Shift 3StartP31194139
      175422Peter7/31/2024Shift 3StartP23351105
      174913Jon7/31/2024Shift 2EndP11374583
      174913Jon7/31/2024Shift 2EndP31194139
      174913Jon7/31/2024Shift 2EndP23351105
      175422Peter7/31/2024Shift 3EndP11423881
      175422Peter7/31/2024Shift 3EndP31234736
      175422Peter7/31/2024Shift 3EndP23351105
      175833Bart7/29/2024Shift 1EndP12420065
      175833Bart7/29/2024Shift 1EndP32734853
      175833Bart7/29/2024Shift 1EndP22502956
      174913Jon7/29/2024Shift 1EndP12298965
      174913Jon7/29/2024Shift 1EndP32584894
      174913Jon7/29/2024Shift 1EndP22713852
      175833Bart7/29/2024Shift 3EndP12659880
      175833Bart7/29/2024Shift 3EndP32595066
      175833Bart7/29/2024Shift 3EndP22302885
      174913Jon7/29/2024Shift 3EndP12853893
      174913Jon7/29/2024Shift 3EndP32771344
      174913Jon7/29/2024Shift 3EndP22429925
      • Anonymous's avatar
        Anonymous
        Not applicable

        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