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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How to calculate the average difference between two measures doing a count on text values

Hi, 

 

I have two measures currently doing a count on a text field shown below

 

Total Apples = COUNTROWS(FILTER('Table',[Category]="Apple"))
Total Pears = COUNTROWS(FILTER('Table',[Category]="Pear"))
 
I am trying to get a average difference between the two measures which is to be used in a card visual to show the average difference for whichever period that have selected in the date range slicer.
 
So just to put it as simply as I can... if the average amount of Apples is 29 and the average number of Pears is 10 the difference would be 19 but I can only seem to get it to work on totals rather than averages.
 
Thanks in advance!
1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

Based on your description, I have created a simple sample like this:

vjianbolimsft_0-1658746075427.png

 

Please try:

 

Difference =

var AverageApples = COUNTROWS(FILTER('Table',[Category]="Apple"))/(DATEDIFF(MIN([Date]),MAX([Date]),DAY)+1)

var AveragePears = COUNTROWS(FILTER('Table',[Category]="Pear"))/(DATEDIFF(MIN([Date]),MAX([Date]),DAY)+1)

Return AverageApples – AveragePears

 

Output:

vjianbolimsft_1-1658746075428.png

 

vjianbolimsft_2-1658746075429.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

Based on your description, I have created a simple sample like this:

vjianbolimsft_0-1658746075427.png

 

Please try:

 

Difference =

var AverageApples = COUNTROWS(FILTER('Table',[Category]="Apple"))/(DATEDIFF(MIN([Date]),MAX([Date]),DAY)+1)

var AveragePears = COUNTROWS(FILTER('Table',[Category]="Pear"))/(DATEDIFF(MIN([Date]),MAX([Date]),DAY)+1)

Return AverageApples – AveragePears

 

Output:

vjianbolimsft_1-1658746075428.png

 

vjianbolimsft_2-1658746075429.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi,

 

This worked perfectly, thank you!

amitchandak
Super User
Super User

@Anonymous , this is count, Avg based on what , Say Date, Month , Region, City etc.

 

Based on the need

 

Averagex(Values(Table[Month Year]), [Total Apples]) - Averagex(Values(Table[Month Year]), [Total Pears ])

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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