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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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]))

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])

@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]))

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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