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
Anonymous
Not applicable

Count rows less than column value

Hi there,

I am trying to do something which should be simple, but I am getting nowhere (as per usual!) 😉

 

I have a column of durations in months (integers from 0 to 120, with many repeated values) and want to count how many are less than or equal to each of the values in the 'Duration' column. Ideally, I also want to then be able to filter visuals by other columns in the table.

 

What is the best way to go about this? I have tried something like this in the table, which I realise is wrong:

=CALCULATE( COUNTROWS( Table ), FILTER( Table, Table[Duration] <= Table[Duration] ))

 

I have also tried a linked DISTINCT durations table, with a similar calculated column in that table:

=CALCULATE( COUNTROWS( Table ), FILTER( Table, Table[Duration] <= [Duration] ))

 

...but this does not appear to work either, and won't allow me to filter on other columns in the original table.

 

Any ideas?

 

Will

 

 

1 ACCEPTED SOLUTION

You are close. Assuming you are filtering on your duration column in a visual, this should give you what you want. 

 

=CALCULATE( COUNTROWS( Table ), FILTER( ALL(Table), Table[Duration] <= max(Table[Duration] )))

 

The addition of the ALL function removes all filters in your visualisation

the addition of the MAX function (or any aggregator for that matter) will detect the current filter context and pass that to your calculate formula. 

Hence the filter function first removes all filters and then reapplies a filter on the Table[Duration] column to be less than or equal to he maximum value in the current filter context. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

5 REPLIES 5

You are close. Assuming you are filtering on your duration column in a visual, this should give you what you want. 

 

=CALCULATE( COUNTROWS( Table ), FILTER( ALL(Table), Table[Duration] <= max(Table[Duration] )))

 

The addition of the ALL function removes all filters in your visualisation

the addition of the MAX function (or any aggregator for that matter) will detect the current filter context and pass that to your calculate formula. 

Hence the filter function first removes all filters and then reapplies a filter on the Table[Duration] column to be less than or equal to he maximum value in the current filter context. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
Anonymous
Not applicable

Hi Matt,

Thanks for that, I will try it out!

Do you know of any accessible tutorials on how to learn more about calculations and measures, CALCULATE and filter contexts?

 

Will

Anonymous
Not applicable

Ha ha! Just noticed your book link at the bottom. I'll check it out! 🙂

 

Will

Yep, that is what I was going to suggest. Smiley Very Happy



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Hi,

 

Please, I created a measure MEDIAN (Dax 2013 version, there's no Median function). I would like to COUNT how many itens in the AVG column that are Greater than the MEDIAN measure. Any idea?

 

My example is here: https://1drv.ms/f/s!As8YC7wZr8RKist1_Ql70SsOKar7yA

 

 

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.