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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

COUNTROWS with a condition value filter

I have data in 5-minute intervals, and I need a measure for the number of hours above a threshold.

 

Hours Above Threshold =
CALCULATE( COUNTROWS ( DataRecords ) / 12,
FILTER ( DataRecords, DataRecords[NumericValue] > 1000 )
)

 

 

 

Here is sample data for 4 hours.  I expect the measure to return (31 periods above 1,000) / 12 =  2.58 hours, but instead I'm getting blank.

 

DateHourEndingIntervalNumericValue
Wednesday, May 8, 20242112295.75
Wednesday, May 8, 20242111389.97
Wednesday, May 8, 20242110644.84
Wednesday, May 8, 2024219639.66
Wednesday, May 8, 20242181237.32
Wednesday, May 8, 20242171341.34
Wednesday, May 8, 20242162667.03
Wednesday, May 8, 20242154486.05
Wednesday, May 8, 20242144993.16
Wednesday, May 8, 20242135018.64
Wednesday, May 8, 20242125018.54
Wednesday, May 8, 20242114979.51
Wednesday, May 8, 202420124984.58
Wednesday, May 8, 202420114592.68
Wednesday, May 8, 202420104301.46
Wednesday, May 8, 20242093263.87
Wednesday, May 8, 20242082993.27
Wednesday, May 8, 20242073323.29
Wednesday, May 8, 20242062320.04
Wednesday, May 8, 20242052042.14
Wednesday, May 8, 20242042013.85
Wednesday, May 8, 2024203859.21
Wednesday, May 8, 20242021043.87
Wednesday, May 8, 20242011928.56
Wednesday, May 8, 20241912258.03
Wednesday, May 8, 202419111145.95
Wednesday, May 8, 202419101531.26
Wednesday, May 8, 20241993109.66
Wednesday, May 8, 20241982985.92
Wednesday, May 8, 20241971160.27
Wednesday, May 8, 2024196653.86
Wednesday, May 8, 2024195450.01
Wednesday, May 8, 2024194564.36
Wednesday, May 8, 2024193489.21
Wednesday, May 8, 2024192266.46
Wednesday, May 8, 2024191286.67
Wednesday, May 8, 20241812323.72
Wednesday, May 8, 20241811307.94
Wednesday, May 8, 20241810459.21
Wednesday, May 8, 2024189430.08
Wednesday, May 8, 2024188675.21
Wednesday, May 8, 20241871046.2
Wednesday, May 8, 20241861415.14
Wednesday, May 8, 20241851964.49
Wednesday, May 8, 20241841338.16
Wednesday, May 8, 20241831631.06
Wednesday, May 8, 20241821975.69
Wednesday, May 8, 20241811942.8

 

Thanks for your help and advice!

1 ACCEPTED SOLUTION
hackcrr
Super User
Super User

Hi, @Anonymous 

I used part of the sample data you provided below:

hackcrr_0-1715471977620.png

I corrected your DAX expression as follows:

Hours Above Threshold = 
VAR ThresholdCount =   
    CALCULATE(  
        COUNTROWS(DataRecords),  
        FILTER(DataRecords, DataRecords[NumericValue] > 1000)  
    )  
RETURN  
    DIVIDE(  
        ThresholdCount * 5,  // 5 minutes per time slot  
        60                  // Convert to hours  
    )

The results are as follows:

hackcrr_1-1715472043640.png

In your Power BI, you are trying to count the number of time slots above a certain threshold (1000) and convert those time slots to hours. However, there are a couple of issues with your DAX expression that need to be fixed.
First, the COUNTROWS function returns the number of rows, not the number of time periods (if each row represents a 5-minute time period). In order to calculate the number of time periods above the threshold, you should use the COUNTROWS function directly, without dividing by 12 (since you haven't converted it to hours).
Then, in order to convert these time periods to hours, you need to know the length of time that each time period represents (5 minutes in your example), and you need to multiply the number of time periods by this length and then divide by 60 (since there are 60 minutes in an hour)

 

 

Best Regards,

hackcrr

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

View solution in original post

2 REPLIES 2
hackcrr
Super User
Super User

Hi, @Anonymous 

I used part of the sample data you provided below:

hackcrr_0-1715471977620.png

I corrected your DAX expression as follows:

Hours Above Threshold = 
VAR ThresholdCount =   
    CALCULATE(  
        COUNTROWS(DataRecords),  
        FILTER(DataRecords, DataRecords[NumericValue] > 1000)  
    )  
RETURN  
    DIVIDE(  
        ThresholdCount * 5,  // 5 minutes per time slot  
        60                  // Convert to hours  
    )

The results are as follows:

hackcrr_1-1715472043640.png

In your Power BI, you are trying to count the number of time slots above a certain threshold (1000) and convert those time slots to hours. However, there are a couple of issues with your DAX expression that need to be fixed.
First, the COUNTROWS function returns the number of rows, not the number of time periods (if each row represents a 5-minute time period). In order to calculate the number of time periods above the threshold, you should use the COUNTROWS function directly, without dividing by 12 (since you haven't converted it to hours).
Then, in order to convert these time periods to hours, you need to know the length of time that each time period represents (5 minutes in your example), and you need to multiply the number of time periods by this length and then divide by 60 (since there are 60 minutes in an hour)

 

 

Best Regards,

hackcrr

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

Bmejia
Super User
Super User

Strange, I copy your table and measure and i got the result you are expecting.  Make sure you don't have other filter in the side pane that might be causing you to get blanks.

Bmejia_0-1715373987552.png

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors