Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Calculate between two columns of hour min and max associated with an hour interval dimension

I need to do a "count if" in the power bi. I have an hour min and max of the agent on the day, I would like to know the representativeness of that time per hour.

For this I have a dimension of hours, min and seconds. But I can't calculate it because DAX doesn't allow conditional sum fuction.

Formula used in excel:
= CONTESES (C: C; "<=" & G2; 😧 D; "> =" & G2)

 

MIN HOUR             |         MAX HOUR         

07:55:00                  |        18:49:00

 

 

 

REPRESENTATIVITY  | RESULT

 

00:00:00                      0
01:00:00                      0
02:00:00                      0
03:00:00                      0
04:00:00                      0
05:00:00                      0
06:00:00                      0
07:00:00                      0
08:00:00                      1
09:00:00                      1
10:00:00                      1
11:00:00                      1
12:00:00                      1
13:00:00                      1
14:00:00                      1 
15:00:00                      1
16:00:00                      1
17:00:00                      1
18:00:00                      1
19:00:00                      0
20:00:00                      0
21:00:00                      0
22:00:00                      0
23:00:00                      0

 

Screenshot_1.png

 

Screenshot_2.pngScreenshot_3.png

1 ACCEPTED SOLUTION

Hi @Anonymous 

 

Sure, try the solution on the attached.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

6 REPLIES 6
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

If you are trying to count hours between start and end then you can use DATEDIFF function 
https://docs.microsoft.com/en-us/dax/datediff-function-dax

 

image.png

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Anonymous
Not applicable

@Mariusz I'm sorry, maybe I didn't express it correctly, I'm sure you will know the answer.

 

 

I need to replicate the table on the right of excel (print 1) for power bi (print 2), but I can't get the quantity separated per hour as I did in the excel formula.

 

 

Screenshot_4.png

 

 

 

 

Screenshot_5.png

 

 

please let me know if i need to send more information

Hi @Anonymous 

 

Sure, try the solution on the attached.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Anonymous
Not applicable

@Mariusz worked perfectly. Thank you 😅

Anonymous
Not applicable

@Mariusz  Just one more doubt. It would be possible to do this same scheme but in a measurement format? Calculating as a column I am unable to filter attributes of these agents such as teams, etc. that are in other tables.

Hi @Anonymous 

 

Sure, the measure would be something like.

Measure = 
COUNTROWS(
    GENERATE(
        Hours,
        VAR __time = Hours[Time]
        RETURN 
            FILTER(
                'Table',
                'Table'[MIN HOUR] <= __time 
                    && 'Table'[MAX HOUR] >= __time
            )
    )
)

 

Just a small note, this sort of calculations tend to be quite slow, so you could create a factless fact table ( in the file you will find DAX Table "factless" but it should be done in Power Query preferably ) and just count the rows, please see the attached for an example.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.