Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
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 start of each one.
Below I show you an example of my table.
Test Name | Data Time | Hour (for each test) |
Test 1 | 16/01/2024 12:00:00 | |
Test 1 | 16/01/2024 13:00:00 | |
Test 1 | 16/01/2024 14:00:00 | |
test 2 | 17/01/2024 15:00:00 | |
Test2 | 17/01/2024 16:00:00 | |
Test 3 | 20/01/2024 09:00:00 | |
Test 3 | 20/01/2024 10:00:00 | |
Test 3 | 20/01/2024 11:00:00 | |
Test 3 | 20/01/2024 12:00:00 |
Thank you very much to anyone who can solve this problem for me.
Bye!
Solved! Go to Solution.
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.
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.
One way is to use a calculated column in Power BI to calculate the duration of each test in hours. Here is an example of a calculated column that calculates the duration of each test in hours:
Duration (hours) = DATEDIFF( MINX(FILTER('Table', 'Table'[Test Name] = EARLIER('Table'[Test Name])), 'Table'[Time]), MAXX(FILTER('Table', 'Table'[Test Name] = EARLIER('Table'[Test Name])), 'Table'[Time]), HOUR )
In this calculated column, 'Table'[Test Name] is the column containing the test names, and 'Table'[Time] is the column containing the time data. The DATEDIFF function calculates the difference between the minimum and maximum times for each test, and the result is returned in hours.
Once you have the calculated column, you can use it to create a measure that calculates the total number of hours spent on each test. Here is an example of a measure that calculates the total number of hours spent on each test:
Total Hours Spent = SUM('Table'[Duration (hours)])
In this measure, 'Table'[Duration (hours)] is the calculated column that contains the duration of each test in hours.
Best regards,
Johannes
Thank you very much, it was very helpfull, but I have another question.
Using your example I got the total hours for a single test, which is good, but I also need the individual hours for the row.
Example
est Name | Data Time | Hour (for each test) |
Test 1 | 16/01/2024 12:00:00 | 0 |
Test 1 | 16/01/2024 13:00:00 | 1 |
Test 1 | 16/01/2024 14:00:00 | 2 |
test 2 | 17/01/2024 15:00:00 | 0 |
Test2 | 17/01/2024 16:00:00 | 1 |
Test 3 | 20/01/2024 09:00:00 | 0 |
Test 3 | 20/01/2024 10:00:00 | 1 |
Test 3 | 20/01/2024 11:00:00 | 2 |
Test 3 | 20/01/2024 12:00:00 | 3 |
Thanks!
Danilo
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
143 | |
72 | |
62 | |
51 | |
48 |
User | Count |
---|---|
206 | |
90 | |
61 | |
59 | |
57 |