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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Calculate Average from all unselected items & compare one selected item vs avg of all unselected

Hi all,

I would like to have one simple line chart in power bi, where I compare one selected item (lets say product) versus average of all other products.

I have table (green one). I want to select in slicer one product - for example product Beta. In chart I will see sales values for this selected product and also I want to see a another line (average of other products = unselected).

I am enclosing two printscreens where you can see my idea in excel file.

Thank you very much for any advice!

Regards

Ondrej Hurtpower_bi_01.JPGpower_bi_02.JPG

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi , @Anonymous 

Try steps  as below:

1.Create a measure in  table

Rest_of_Prod_Avg =
CALCULATE (
    SUM ( 'Table'[sales] ),
    EXCEPT ( ALL ( 'Table'[Product] ), FILTERS ( 'Table'[Product] ) )
)
    / COUNTROWS ( EXCEPT ( ALL ( 'Table'[Product] ), FILTERS ( 'Table'[Product] ) ) )

 

2.Create another  calculate table:

Legand = UNION(DISTINCT('Table'[Product]),{"Rest"})

Add a measure here:

Measure =
IF (
    NOT "Rest" IN FILTERS ( 'Legand'[Product] ),
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( 'Table', 'Table'[Product] IN FILTERS ( 'Legand'[Product] ) )
    ),
    [Rest_of_Prod_Avg]
)

 

3.Adding measure to visualizations

It  will show as below:

82.png

 

 

Here is a demo:

PBIX URL 

 

Best Regards,
Community Support Team _ Eason
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-easonf-msft
Community Support
Community Support

Hi , @Anonymous 

Try steps  as below:

1.Create a measure in  table

Rest_of_Prod_Avg =
CALCULATE (
    SUM ( 'Table'[sales] ),
    EXCEPT ( ALL ( 'Table'[Product] ), FILTERS ( 'Table'[Product] ) )
)
    / COUNTROWS ( EXCEPT ( ALL ( 'Table'[Product] ), FILTERS ( 'Table'[Product] ) ) )

 

2.Create another  calculate table:

Legand = UNION(DISTINCT('Table'[Product]),{"Rest"})

Add a measure here:

Measure =
IF (
    NOT "Rest" IN FILTERS ( 'Legand'[Product] ),
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( 'Table', 'Table'[Product] IN FILTERS ( 'Legand'[Product] ) )
    ),
    [Rest_of_Prod_Avg]
)

 

3.Adding measure to visualizations

It  will show as below:

82.png

 

 

Here is a demo:

PBIX URL 

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This solution worked great for one filter.  Is there a way to add a second filter to the dax?  For instance, lets say we wanted to add "region" to the example above?  I work in education so I'm constantly working with comparisons of students with multiple variables, but I think the principles would be the same, so for consistency, I'd like to see if there is a solution for an additional column showing US or Europe rather than creating a new dataset.

For these purposes, I guess I'd like to filter and show the calculation for alpha in the US compared to (all products in Europe + all non-alpha in the US).  

 

thank you for any help you can give.

Josh

Anonymous
Not applicable

@v-easonf-msft 

Thank you very much, that is exactly what I wanted!! Great, thank you!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.