Forum Discussion
Count Specific Time Slots within Time range
- 4 years ago
Hi Gsar
Try this measure:
Count Time Slot = VAR _A = ADDCOLUMNS( 'Time slots', "C", COUNTROWS( FILTER( 'Table Transactions', 'Time slots'[Time Start] < 'Table Transactions'[Time END] && 'Time slots'[Time End] > 'Table Transactions'[Time Start] ) ) ) RETURN SUMX( _A, [C] )Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
I worked on top of your solution and got the expected result.
I changed the measure to the following
Measure =
VAR _start =
MAX ( 'Time slots'[Time Start] )
VAR _end =
MAX ( 'Time slots'[Time End] )
VAR _count =
COUNTROWS (
FILTER (
Transactions,
_start< Transactions[Time END]
&& _end > Transactions[Time Start]
)
)
RETURN
_count
Now I am getting the following results which looks correct?
| Time Start | Time End | Measure |
| 08:00:00 | 08:30:00 | 1 |
| 08:30:00 | 09:00:00 | 2 |
| 09:00:00 | 09:30:00 | 4 |
| 09:30:00 | 10:00:00 | 4 |
| 10:00:00 | 10:30:00 | 4 |
| 10:30:00 | 11:00:00 | 5 |
| 11:00:00 | 11:30:00 | 5 |
| 11:30:00 | 12:00:00 | 4 |
| 12:00:00 | 12:30:00 | 4 |
| 12:30:00 | 13:00:00 | 3 |
| 13:00:00 | 13:30:00 | 4 |
| 13:30:00 | 14:00:00 | 4 |
| 14:00:00 | 14:30:00 | 3 |
| 14:30:00 | 15:00:00 | 3 |
| 15:00:00 | 15:30:00 | 3 |
| 15:30:00 | 16:00:00 | 3 |
| 16:00:00 | 16:30:00 | 3 |
| 16:30:00 | 17:00:00 | 3 |
| total | 3 |
My issue now is in the total.
The total should be 62 but I am getting 3. I should be able to use this measure to count the rows if I drop it to the weeks or the random variable.
For example:
| c1 | 15 |
| c2 | 20 |
| c3 | 21 |
| c4 | 7 |
| total | 62 |
The above is just an example but I hope that you understand the meaning.
Please let me know whether I should open another thread for this aditional question.
I would be happy to accept your answer as correct the way it is since you helped immensely to build the one I was looking for.