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
pramodkumbhare
Frequent Visitor

Count of Account having Revenue above or equal to Average Revenue

Hi All,

 

I am trying to get count of Account having Revenue above or equal to Average Revenue, but not able to do so. Please if someone can let me know if I am doing something wrong here.

 

 

Here is what i want, count >= Avg customer, in below case its 3. Below data is from Excel.

 

 

Account IDSalesUnique AccountAvg Revenue>= avg customer< avg customer
1308212546.14285710
278412546.14285701
11000   
322212546.14285701
4525612546.14285710
5138012546.14285701
68612546.14285701
7691312546.14285710
      
   Total34

 

I am creating two measures as below:

1. Avg Sale by Accounts = CALCULATE(DIVIDE(sum(Table1[Sales]),DISTINCTCOUNT(Table1[Account ID])))

2. No. of Acc under AVG = CALCULATE( DISTINCTCOUNT(Table1[Account ID]),filter(Table1,[Sales] <= [Avg Sale by Accounts]))

 

But the result is not coming as execpted, it giving 7, which are total unique accounts. i want 3 there. See below pbix screenshot.

 

Please help 🙂

 

 

Capture.PNG

 

 

 

 

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

HI @pramodkumbhare,

 

You could just add these calcuated columns to your table and then add a SUM measure over the top

 

Above Average = 
VAR Sales = CALCULATE(SUM([Sales]),ALL('Table') )
VAR RowCount = CALCULATE(DISTINCTCOUNT('Table'[Account ID]),ALL('Table'))
Return IF([Sales]>=DIVIDE(Sales,RowCount),1,0)
Below Average = 
VAR Sales = CALCULATE(SUM([Sales]),ALL('Table') )
VAR RowCount = CALCULATE(DISTINCTCOUNT('Table'[Account ID]),ALL('Table'))
Return IF([Sales]<DIVIDE(Sales,RowCount),1,0)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
mattbrice
Solution Sage
Solution Sage

I would solve this problm with measures as I believe the calculated column solution won't provide the answer you want. I'll explain below.   I would make a few measures:

Total Sales = SUM ( Table1[Sales] )

Count of Accounts = DISTINCTCOUNT ( Table1[AccountID] )

Avg Per Account = [Total Sales] / [Count of Accounts]

Avg over all accounts = CALCULATE( [Avg Per Account], ALL(Table1[Account ID] ) )

No. Accounts under or equal Average =
CALCULATE ( COUNTROWS ( VALUES ( Table1[Account ID] ) ),
FILTER (
VALUES ( Table1[Account ID] ),
[Total Sales] <= [Avg over all accounts]
)
)
No. Accounts over Average =
CALCULATE (
COUNTROWS ( VALUES ( Table1[Account ID] ) ),
FILTER (
VALUES ( Table1[Account ID] ),
[Total Sales] > [Avg over all accounts]
)
)

 Then put Table1[AccountID] on the rows, then select the measures you want.

 

Couple of points about the caclulated column solution.  First, the calculated column is comparing the row's sales value to average; not the total for the AccountID.  So this would lead to errors in marking rows above or below average.  Second, becuase an AccountID has multiple sales, the same AccountID will be counted either above or below average for every sale and not once per AccountID which is what i think the OP is wanting.  OP - let me know if I am interpresting things right.

 

And FYI, calculated columns are computed at data load time and therefore have no filter context, only a row context.   Row contexts are only transitioned to a filter context if you use CALCULATE, CALCULATETABLE, or one of the other table functions.  This is a long winded way of saying that instead of :

VAR Sales = CALCULATE(SUM([Sales]),ALL('Table') )

you can just do:

VAR Sales = SUM ( Table1[Sales] )

 and get the same result.

Phil_Seamark
Employee
Employee

HI @pramodkumbhare,

 

You could just add these calcuated columns to your table and then add a SUM measure over the top

 

Above Average = 
VAR Sales = CALCULATE(SUM([Sales]),ALL('Table') )
VAR RowCount = CALCULATE(DISTINCTCOUNT('Table'[Account ID]),ALL('Table'))
Return IF([Sales]>=DIVIDE(Sales,RowCount),1,0)
Below Average = 
VAR Sales = CALCULATE(SUM([Sales]),ALL('Table') )
VAR RowCount = CALCULATE(DISTINCTCOUNT('Table'[Account ID]),ALL('Table'))
Return IF([Sales]<DIVIDE(Sales,RowCount),1,0)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks for this... It worked 🙂

Cheers.

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.