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 number of times one is bigger than the other

Hello,

 

My data looks like this:

 

StoreProductTime stampWeight
Aa12-Mar-2010
Aa15-Mar-2011
Ab15-Apr-2012
Ba15-May-209
Bb15-Apr-209


I would like to create a visual that shows how many times the average weight of Product a is more than the average weight of b, same as b, or less than b.

The desired output looks like this:

 # of times
average(a) > average(b)0
average(a) = average(b)1
average(a) < average(b)1

 

I have trouble calculating the count and the average at the same time, because different products and stores can have different time stamps. How can I go about solving this issue?

 

Thank you very much for your time. 

8 REPLIES 8
Anonymous
Not applicable

Hello,

The averages of the weights are calculated by store.

For example, in Store A, the average weight of product a is (10+11)/2 = 10.5, and the average weight of product b is 12. In this instance, 10.5 < 12, it counts as 1 under average(a) < average(b). Does this make sense? @Ashish_Mathur @lbendlin 

StoreProductTime stampWeight
Aa12-Mar-2010
Aa15-Mar-2011
Ab15-Apr-2012
Ba15-May-209
Bb15-Apr-209

Hi,

There could be 100's of products in each store.  If there are 100 products in a store, then are you expxecting the average weight of each product to be compared with the other 99?  I really do not know the final output you want (especially when the number of products per store are quite many).


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur,

 

Yes there are many products in each store, but each time, I am only comparing the average weight of two products. I am hoping that I can control which two products with two filters. 

However, if filtering is not possible, then hard-coding which two products to compare is an acceptable workaround (I just can't even figure out how to do this!).  

Hi  @Anonymous ,

 

Create a table as below:

Screenshot 2020-10-16 084314.png

Then create 4 measures as below:

count_average(a) < average(b) = 
CALCULATE(DISTINCTCOUNT('Table'[Difference]),FILTER('Table','Table'[Difference]<0))+0
count_average(a) > average(b) = 
CALCULATE(DISTINCTCOUNT('Table'[Difference]),FILTER('Table','Table'[Difference]>0))+0
count_average(a) equals average(b) = 
CALCULATE(DISTINCTCOUNT('Table'[Difference]),FILTER('Table','Table'[Difference]=0))+0
Measure = 
SWITCH(SELECTEDVALUE('Table (2)'[Column1]),
"average(a) > average(b)",'Table'[count_average(a) > average(b)],
"average(a) = average(b)",'Table'[count_average(a) equals average(b)],
"average(a) < average(b)",'Table'[count_average(a) < average(b)])

And you will see:

Screenshot 2020-10-16 084713.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

 

Anonymous
Not applicable

Thank you @v-kelly-msft, but your "Difference" calculation doesn't seem correct. The difference between products a and b in store B should be 0, but you are showing 9?

 

hi_potato_salad_0-1602855117139.png

 

 

Hi @Anonymous ,

 

Sorry for the late reply.

I didnt quite get your point,but difference here is showing 0 not 9..

Screenshot 2020-10-29 134345.png

 

Check my .pbix attached.

 

Best Regards,
Kelly

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

 

Ashish_Mathur
Super User
Super User

Hi,

How did you arrive at the result of 0,1,1?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

this smells like a bad case of the Permutitis .

 

you have three values of a - that means you have six different ways of computing an "average of a"

 

with b you have two values, ergo three permutations. That gives you 18 comparisons. Is that really what you want?

 

Hopefully you have some more rules that better describe the ask.

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.