Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
hey peeps,
How do I calculate the time duration by the same ID over difference dates?
Transaction Date | Date & Time | ID | In 1 / Out 0 |
9/5/2018 | 9/5/2018 5:18:20 PM | 22985 | 1 |
6/2/2017 | 6/2/2017 12:00:00 PM | 1572 | 1 |
7/2/2017 | 7/2/2017 4:00:00 PM | 1572 | 0 |
8/2/2017 | 8/2/2017 10:00:00 AM | 1572 | 1 |
11/2/2017 | 11/2/2017 12:00:00 PM | 1572 | 0 |
Expected Output as below
Example
1572 clocks in on 6/2 12pm, and clocks out on 7/2 4pm, = 24 + 4 = 28 hours
1572 clocks in on 8/2 10am, and clocks out on 11/2 12pm, = 24 + 24 +24 + 4 = 78 hours
Total for 1572 = 28 + 78 = 106 hours
22985 clocks in once on 9/5, but there's no nearest clock out, hence = 0.
FIN | In Count | Out Count | Total Duration |
1572 | 2 | 2 | 28 + 74 = 102 hours |
22985 | 1 | 0 | 0 cause no nearest out |
Solved! Go to Solution.
Hi @Anonymous,
First new a calculated column:
Duration = DATEDIFF ( IF ( Test2[In 1 / Out 0] = 0, CALCULATE ( MAX ( Test2[Date & Time] ), FILTER ( ALLEXCEPT ( Test2, Test2[ID] ), Test2[Date & Time] < EARLIER ( Test2[Date & Time] ) && Test2[In 1 / Out 0] = 1 ) ) ), Test2[Date & Time], HOUR )
Then, create below measures:
In Count = CALCULATE(COUNT(Test2[In 1 / Out 0]),FILTER(Test2,Test2[In 1 / Out 0]=1))+0 Out Count = CALCULATE(COUNT(Test2[In 1 / Out 0]),FILTER(Test2,Test2[In 1 / Out 0]=0))+0 Total Duration = SUM(Test2[Duration])+0
Use a Table visual o display data.
Best regards,
Yuliana Gu
Hi @Anonymous,
First new a calculated column:
Duration = DATEDIFF ( IF ( Test2[In 1 / Out 0] = 0, CALCULATE ( MAX ( Test2[Date & Time] ), FILTER ( ALLEXCEPT ( Test2, Test2[ID] ), Test2[Date & Time] < EARLIER ( Test2[Date & Time] ) && Test2[In 1 / Out 0] = 1 ) ) ), Test2[Date & Time], HOUR )
Then, create below measures:
In Count = CALCULATE(COUNT(Test2[In 1 / Out 0]),FILTER(Test2,Test2[In 1 / Out 0]=1))+0 Out Count = CALCULATE(COUNT(Test2[In 1 / Out 0]),FILTER(Test2,Test2[In 1 / Out 0]=0))+0 Total Duration = SUM(Test2[Duration])+0
Use a Table visual o display data.
Best regards,
Yuliana Gu
Brilliant!!!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
97 | |
77 | |
63 | |
55 |
User | Count |
---|---|
143 | |
109 | |
89 | |
84 | |
66 |