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
a4apple
Helper I
Helper I

How to find count of rows greater than average value?

Hello Everyone,

 

I have a Measure that calculates the Average of a value in the table.

 

Now I want to find out the count of records that are greater than the average value.

 

I want to group the average by Country and date and then find the count of records. How can I write the measure that counts the records in such fashion?

 

table structure is like below:

 

Sales : 

CustomerKey  DateKey    Country SalesValue

       1           20160101     US         1.56

       2           20160101     US         2.20

       3           20160101     CA           0

       1           20160102     US         5.20

 

Average := AVERAGEX(FILTER('Sales', 'Sales'[SalesValue] > 0), 'Sales'[SalesValue])

 

Count := CALCULATE(COUNTROWS('Sales'), [SalesValue] > [Average]) --> This didn't work gave error

 

Count := COUNTROWS(FILTER('Sales', 'Sales'[SalesValue] > [Average])) --> This gives the value for all countries. It is not considering US Average for US only Stores / CA average for CA only stores and date as well is not being considered....

 

Thanks in advance.

7 REPLIES 7

Hello,

 

I am working on some kind of scenario like this.

 

If you got a solution, could you give me?


@a4apple wrote:

Hello Everyone,

 

I have a Measure that calculates the Average of a value in the table.

 

Now I want to find out the count of records that are greater than the average value.

 

I want to group the average by Country and date and then find the count of records. How can I write the measure that counts the records in such fashion?

 

table structure is like below:

 

Sales : 

CustomerKey  DateKey    Country SalesValue

       1           20160101     US         1.56

       2           20160101     US         2.20

       3           20160101     CA           0

       1           20160102     US         5.20

 

Average := AVERAGEX(FILTER('Sales', 'Sales'[SalesValue] > 0), 'Sales'[SalesValue])

 

Count := CALCULATE(COUNTROWS('Sales'), [SalesValue] > [Average]) --> This didn't work gave error

 

Count := COUNTROWS(FILTER('Sales', 'Sales'[SalesValue] > [Average])) --> This gives the value for all countries. It is not considering US Average for US only Stores / CA average for CA only stores and date as well is not being considered....

 

Thanks in advance.


 

Thank You.

HI @tulasi_pbi1988 

 

This should work for you

 

Count = 
VAR MyAverage = CALCULATE(AVERAGE(Table1[SalesValue]),ALL(Table1))
VAR MYSales = SUM(Table1[SalesValue])
RETURN
CALCULATE(COUNTROWS('Table1'), FILTER('Table1',MYSales > MyAverage))

And this is what it looks like

 

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Sridhar_Cheruvu
Frequent Visitor

Hi,

 

Could you get the solution for this problem?

Even I am looking for a similar kind of solution.

 

Please share if you could resolve your issue.

 

Thanks,

Sri.

Hi @Sridhar_Cheruvu

 

Not yet. Will let you know once I find a solution.

 

Cheers

 

CheeenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!
CheenuSing
Community Champion
Community Champion

Hi @a4apple

 

Can you please post more data and the final visual and the output you expect.

 

 

Post it in one drive and share.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!
a4apple
Helper I
Helper I

FYI, I am trying to do this in SSAS Tabular 1200 Compatibility.

Hi @a4apple

 

What if you just create a measure which counts the rows?

 

And then you can use the measure in the table or visual?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

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.