Forum Discussion

jayman's avatar
jayman
Regular Visitor
1 year ago
Solved

Calculating days in specific location for devices

I am trying to calculate the days a device spent in a specific location. I figured it out in excel while venting my data. But I cannot figure out how to translate it over to Power BI for my reports. ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Thanks for the reply from danextian and Kedar_Pande, please allow me to provide another insight.
    Hi jayman ,

    Add an index column.

     


    Create the following calculated columns.

    Days in L46 = 
    VAR currentIndex = 'Table'[Index]
    VAR nextC_ATTRIBUTE1 =
        MAXX (
            FILTER ( 'Table', 'Table'[Index] = currentIndex + 1 ),
            'Table'[C_ATTRIBUTE1]
        )
    VAR nextTRANSATION_DATE =
        MAXX (
            FILTER ( 'Table', 'Table'[Index] = currentIndex + 1 ),
            'Table'[TRANSACTION_DATE]
        )
    RETURN
        IF (
            nextC_ATTRIBUTE1 = 'Table'[C_ATTRIBUTE1],
            IF (
                'Table'[SUBINVENTORY_CODE] = "L46",
                DATEDIFF ( nextTRANSATION_DATE, 'Table'[TRANSACTION_DATE], DAY ),
                0
            ),
            0
        )
    Total Days in L46 = 
    SUMX (
        FILTER ( 'Table', 'Table'[SERIAL_NUMBER] = EARLIER ( 'Table'[SERIAL_NUMBER] ) ),
        'Table'[Days in L46]
    )


    The final result is as follows.

     

    Please see the attahed pbix for reference.
     
    Best Regards,
    Dengliang Li

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.