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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
stefanot
Frequent Visitor

Averageif based con current line

Hallo, I've found similar questions to mine in the forum, but it looks like none of them is really what I'm looking for

 

In PowerPivot/DAX I want to create a measure that represents an averageif of sales for each kind of products, like in the example below: 

 

ProductSALESaverageif
drink32
drink12
food44

 

 

In other discussions I see solutions like 

AverageNumberofSALES=Calculate(average(Table[SALES]),Filter(Table, Table[Product]="drink"))

 

but in my case instead of inputing "drink" i'd like to tell in DAX "current value of any single row"

 

thanks

 

 

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

Hi @stefanot ,

 

Please try:

AverageNumberofSALES = CALCULATE(AVERAGE('Table'[SALES]),ALLEXCEPT('Table','Table'[Product]))

Final output:

vjianbolimsft_0-1668412707970.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

6 REPLIES 6
v-jianboli-msft
Community Support
Community Support

Hi @stefanot ,

 

You can achieve this by changing the aggregation of SALES directly:

vjianbolimsft_0-1668414032630.png

Output:

vjianbolimsft_0-1668414422090.png

 

Besides, this question is beyond the topic discussed at the beginning of the thread. So to be able to better help other users, if you still have any other questions, please consider marking the replies that are useful to you and creating a thread about the new topic, which will allow the thread to be addressed more efficiently.

Thanks in advance!

 

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.

v-jianboli-msft
Community Support
Community Support

Hi @stefanot ,

 

Please try:

AverageNumberofSALES = CALCULATE(AVERAGE('Table'[SALES]),ALLEXCEPT('Table','Table'[Product]))

Final output:

vjianbolimsft_0-1668412707970.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.

This works perfectly, thanks!

let me take the chance for an additional question though:

 

imagine you have an additional variable of status: 

PRODUCTSTATUSSALES

DRINKSOLD1
DRINKPROPOSED3
FOODPROPOSED4

 

how can you get the average if that changes depending on whether you filter by status (eg the average of only sold drinks would become 1)?

stefanot
Frequent Visitor

a calculated column.

the objective later on is to create a measure that can calculate the difference between the sales of any selected line in the pivot and the fixed number (so not changing based on how you play with the pivot) of average sales of that specific product.

 

hope this clarifies, thanks for your message!

[SalesAverageIf] = // calc column
var CurrentProd = T[Product]
var Result =
    AVERAGEX(
        FILTER(
            T,
            T[Product] = CurrentProd
        ),
        T[Sales]
    )
return
    Result
daXtreme
Solution Sage
Solution Sage

You didn't say what you really want, a measure or a calculated column...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.