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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
theotejada
Frequent Visitor

Count Rows After a Date Specified on a Measure

I have a table with a similar look like this (we'll name this table as 'Sample'):

Date/TimeInsignificant Values
10/17/2020 05:02:38 PM

lorem

10/17/2020 05:03:31 PMipsum
10/17/2020 05:04:25 PMdolor
10/17/2020 05:06:12 PMsit
12/14/2020 04:30:57 AMamet
12/14/2020 04:34:43 AMconsectetur

12/14/2020 04:39:42 AM

adipiscing
12/14/2020 04:43:59 AMelit
12/14/2020 04:44:51 AMsed

 

What I want is a measure that will count the number of rows for this table if the date/time is beyond a date/time placed on a measure (in this case, [M_ReferenceDate] = 12/14/2020 03:30:53 AM).

 

I am expecting a count of 5 on this example, but I'm getting the count of the entire rows (9) without satisfying the condition using the formula COUNTROWS(FILTER('Sample','Sample'[Date/Time] > [M_ReferenceDate])). I even tried creating a column with expression IF('Sample'[Date/Time] > [M_ReferenceDate], 1, 0) to see if I can have this as backup (then counting the 1s), but it results to all rows being 1 instead of only the last 4.

 

I'm still a beginner on Power BI, and searched for various solutions related to this one, but those solutions still results to the same problem.

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@theotejada 

Works fine on my side on the data you provided earlier. See it all at work in the attached file.

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

4 REPLIES 4
AlB
Community Champion
Community Champion

@theotejada 

Works fine on my side on the data you provided earlier. See it all at work in the attached file.

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Hi @AlB,

 

Actually, it's my data/Power BI acting up, not leading to the expected results. I tried to make another Power BI Dashboard using the same data, and it works as expected. I don't know why, but I think that will be the solution for now.

 

Thanks for your help. 

AlB
Community Champion
Community Champion

Hi @theotejada 

Are you sure  [M_ReferenceDate]  is of type datetime?  Is the Sample[Date/Time] of type datetime?

Try this, and it should work with the rest as you have it:

M_ReferenceDate = CONVERT("12/14/2020 03:30:53 AM", DATETIME)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Hi @AlB

 

I am sure that [M_ReferenceDate] is of type DATETIME. I had a prior calculation having the value of [M_ReferenceDate], which is:

M_ReferenceDate = CALCULATE(MAX('Another Table'[Date/Time]), FILTER('Another Table', 'Another Table'[Status] = "Started"))

 

Where Another Table has a sample value below: Note: I'm getting posting problems whenever I tried to insert a table, so I just made it manually below

 

Date/Time                         Status

08/15/2020 12:49:32 PM  Started

08/15/2020 02:12:47 PM  Ended

09/15/2020 06:59:06 PM  Started

09/15/2020 08:36:09 PM  Ended

11/11/2020 11:46:11 AM  Started

11/11/2020 12:24:01 PM  Ended

12/14/2020 03:30:53 AM  Started

12/14/2020 05:05:25 AM  Ended

 

The above calculation for [M_ReferenceDate] gets the highest value, in this case, 12/14/2020 03:30:53 AM and is formatted as DATETIME.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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