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
cyclist007
Responsive Resident
Responsive Resident

Create a Calculated Column RowCount for filtering data

Hi,

 

I have a use case where i have data for multiple sensors (for multiple days). In Power BI, I would like to plot this as a trend of sensor readings (values). One issue i have with the data is on certain days some of the sensors are not used but still have a few readings (which would count as anomolies). Normally only if there are more than say 5 readings on a particular day the trend would be useful to plot and see.

I would like to write the logic for the calculated column which has thr row count for that sensor and that date, so that i can use this column and filter out all dates & sensors which have less than say 5 readings.

Example:

Sensor NameDate-TimeValueCalculatedColumn
Sensor 104-29-2020 3:00am1.52
Sensor 104-29-2020 4:00am1.752
Sensor 204-29-2020 1:00am1.56
Sensor 204-29-2020 2:00am1.656
Sensor 204-29-2020 3:00am1.756
Sensor 204-29-2020 4:00am1.856
Sensor 204-29-2020 5:00am1.756
Sensor 204-29-2020 6:00am1.656
Sensor 304-29-2020 1:00am1.57
Sensor 304-29-2020 2:00am1.657
Sensor 304-29-2020 3:00am1.757
Sensor 304-29-2020 4:00am1.857
Sensor 304-29-2020 5:00am1.757
Sensor 304-29-2020 6:00am1.657
Sensor 304-29-2020 7:00am1.627

 

From the above table if i just put a filter saying calculatedcolumn >5 it would filter out Sensor 1 data on chart/visual.

 

I have tried using 

Reading Count Column = COUNTROWS(FILTER(Query1, Query1[Sensor]=Query1[Sensor] & Query1[LocalTime by Date]=(Query1[LocalTime by Date])))
but it does not seem too work.

Would appreciate if someone can suggest what am I doing wrong. Thanks

 

 

1 ACCEPTED SOLUTION

@cyclist007 

Try like

countx(filter(table,table[Sensor Name]=earlier(table[Sensor Name]) && table[Date]=earlier(table[Date])),[Value])

 

Have a date column that will make it easy

 

Date = [date-time].date

or

Date = date(year( [date-time]),Month( [date-time]),Day( [date-time]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@cyclist007 , Try a new column like

countx(filter(table,table[Sensor Name]=earlier(table[Sensor Name])),[Value])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak, Thanks for quick reply. It seems to be working, did not know about "Earlier" and its usefulness!

 

I have one more question  to do this completely: I need to filter (group by) multiple columns: Just not sensor_name, even the date (& possibly one other field: location) .... & does not seem to work. Can you suggest how multiple filter critera can be added with earlier?

 

@cyclist007 

Try like

countx(filter(table,table[Sensor Name]=earlier(table[Sensor Name]) && table[Date]=earlier(table[Date])),[Value])

 

Have a date column that will make it easy

 

Date = [date-time].date

or

Date = date(year( [date-time]),Month( [date-time]),Day( [date-time]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks @amitchandak that worked (and thanks for adding the extra tip on using .date)

Just one other thing is there any drawback/advantage in using Countrows instead of CountX in this case? I have read Countrows is supposed to be more efficent/better from a performance perspective.

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