Forum Discussion

DaniloMuni's avatar
DaniloMuni
New Member
2 years ago
Solved

DAX formula for working hour for each test from data.

Hello Everyone,   I need to figure out how many hours are spent on each individual test. Each test has a different start date, and we need to indicate the hours elapsed for each test from the star...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi DaniloMuni 

     

    Please try this:

    Add a calculate column:

    Hour = 
    VAR _PreviousTime =
        CALCULATE (
            MIN ( Data[Date Time] ),
            FILTER (
                ALLSELECTED ( 'Data' ),
                'Data'[Test Name] = EARLIER ( Data[Test Name] )
                    && 'Data'[Date Time] < EARLIER ( Data[Date Time] )
            )
        )
    RETURN
        IF (
            _PreviousTime = BLANK (),
            0,
            DATEDIFF ( _PreviousTime, 'Data'[Date Time], HOUR )
        )

    The result is as follow:

    If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

    How to provide sample data in the Power BI Forum

    How to Get Your Question Answered Quickly

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards

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