Forum Discussion

mnb_dk's avatar
mnb_dk
Helper I
2 years ago
Solved

Exclude values in Average calculation

Hi there

 

I have a matrix showing product sales and I would like to see the average unit cost for each product. The problem is that the average is incorrect since it includes lines where QTY = blank/0 and includes these in the average calculation. 

 

I can filter on the QTY visual to "Show items when the value is not blank". However it only works if I include the "Size" data point in the matrix and I would like not to show this, so I only have two levels in the matrix:


1. Product ID

2. Color

3. Size (I DONT WANT TO SEE THIS IN MY MATRIX)

 

I would expect to see two colors with an average of 138,36 each and also in total. 

 

Below data example:

ProductColorSizeUnit costsQTY
Product 1BlackL/XL138,3646
Product 1BlackM/L138,3688
Product 1BlackS/M138,36104
Product 1BlackXS/S138,3666
Product 1GreenL129,72 
Product 1GreenL/XL138,3671
Product 1GreenM129,72 
Product 1GreenM/L138,36179
Product 1GreenS129,72 
Product 1GreenS/M138,36216
Product 1GreenXL129,72 
Product 1GreenXS129,72 
Product 1GreenXS/S138,36142
Product 1GreenXXL129,72 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  mnb_dk ,

     

    Thanks for the reply from HotChilli , please allow me to provide another insight: 

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    AVERAGEX(
        FILTER(ALL('Table'),
        'Table'[Color]=MAX('Table'[Color])&&[QTY]<>BLANK()),[Unit costs])

    2. Result:

     

    Best Regards,

    Liu Yang

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

8 Replies

  • HotChilli's avatar
    HotChilli
    Community Champion

    You have a few alternatives:

    1. Write your own average measure excluding the rows where qty is empty/0

    or

    2. Put a visual filter on the matrix to filter in the the qty values you want , for example, include only qty > 0

    • mnb_dk's avatar
      mnb_dk
      Helper I

      Using the visual filter by excluding qty values >0 makes no different. Only if I keep the "Size" in the visual. If I remove it, it makes no difference.

  • HotChilli's avatar
    HotChilli
    Community Champion

    You want to include qty > 0 , not exclude them.  Post your pbix and I'll have a look at it

    • mnb_dk's avatar
      mnb_dk
      Helper I

      My pbix contains sensitive data, but the example data provided above should be sufficient?

  • HotChilli's avatar
    HotChilli
    Community Champion

    It will be sufficient.  If you use it in a pbix and post it, I'll see why my suggestions are not working for you.

    • mnb_dk's avatar
      mnb_dk
      Helper I

      Ok I will try. But for some reason I can't upload files here?

  • HotChilli's avatar
    HotChilli
    Community Champion

    Put it on 3rd party site (dropbox or similar) and post the link here

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  mnb_dk ,

     

    Thanks for the reply from HotChilli , please allow me to provide another insight: 

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    AVERAGEX(
        FILTER(ALL('Table'),
        'Table'[Color]=MAX('Table'[Color])&&[QTY]<>BLANK()),[Unit costs])

    2. Result:

     

    Best Regards,

    Liu Yang

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