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

Average - Distinct

Spool =
CALCULATE(
    AVERAGE('AllInvoiceDetails'[Quantity]),
    'Product'[ProductGroup] = { "Spool" }
)
 
I have the above formula but it is not working.
In the Product Group there may be 2 values with "Spool"
I think I just need to add a Distinct but I keep getting errors.
 
Where there is 2, I am getting double the number.
 
Can someone tell me how to add a Distinct.
 
Thanks
 
 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Damian911 ,

I am glad to help you.
@Jihwan_Kim ,Thank you very much for your help with this case!
I've come up with another solution that I'd like to share.

Based on your description, I think you can try to change the DAX code to this:

 

Spool = 
CALCULATE(
    AVERAGE('AllInvoiceDetails'[Quantity]),
    FILTER(
        'Product',
        'Product'[ProductGroup] = "Spool"
    )
)

 

I created the following test data as you described it.

vjtianmsft_0-1713855749273.pngvjtianmsft_1-1713855764695.png

It is recommended to use the filter function in the calculate function to filter out a separate range for calculation (from the Product table to filter out ProductGroup = "Spool" rows of data), then only ProductGroup for the "Spool" rows will be used in the previous average method. (Requires a relationship between the tables.)

Using the filter function, it is possible to individually restrict a calculation range (creating a new table), which does not affect the other dax expressions of the model.

Here's what happens when no relationship is created between tables:

vjtianmsft_2-1713855808367.png

vjtianmsft_3-1713855886526.png

The results for both are incorrect.
When a relationship is established between two tables:

vjtianmsft_4-1713855927008.png

 



vjtianmsft_5-1713855927009.png

 

The above code not only calculates the average value in the "spool" according to the filter range, but also calculates the duplicate ID (value 2) records only once.
The above measure using the filter function is correct, and correspondingly, the following expression does not change the filter range before and after the relationship is created.

vjtianmsft_6-1713856088292.png

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

Best Regards,
Carson Jian,
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

2 REPLIES 2
Anonymous
Not applicable

Hi @Damian911 ,

I am glad to help you.
@Jihwan_Kim ,Thank you very much for your help with this case!
I've come up with another solution that I'd like to share.

Based on your description, I think you can try to change the DAX code to this:

 

Spool = 
CALCULATE(
    AVERAGE('AllInvoiceDetails'[Quantity]),
    FILTER(
        'Product',
        'Product'[ProductGroup] = "Spool"
    )
)

 

I created the following test data as you described it.

vjtianmsft_0-1713855749273.pngvjtianmsft_1-1713855764695.png

It is recommended to use the filter function in the calculate function to filter out a separate range for calculation (from the Product table to filter out ProductGroup = "Spool" rows of data), then only ProductGroup for the "Spool" rows will be used in the previous average method. (Requires a relationship between the tables.)

Using the filter function, it is possible to individually restrict a calculation range (creating a new table), which does not affect the other dax expressions of the model.

Here's what happens when no relationship is created between tables:

vjtianmsft_2-1713855808367.png

vjtianmsft_3-1713855886526.png

The results for both are incorrect.
When a relationship is established between two tables:

vjtianmsft_4-1713855927008.png

 



vjtianmsft_5-1713855927009.png

 

The above code not only calculates the average value in the "spool" according to the filter range, but also calculates the duplicate ID (value 2) records only once.
The above measure using the filter function is correct, and correspondingly, the following expression does not change the filter range before and after the relationship is created.

vjtianmsft_6-1713856088292.png

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

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

Jihwan_Kim
Super User
Super User

Hi,

Please share your sample pbix file's link.

Or, please try something like below whether it suits your requirement.

 

Spool =
CALCULATE (
    AVERAGE ( 'AllInvoiceDetails'[Quantity] ),
    'Product'[ProductGroup] IN { "Spool" }
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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