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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
AldoMF
Frequent Visitor

How to add an "average if" column to query

I have this kind of data:

NamePositionMargin
DaniProc9.2%
ThomasSales62.4%
KateSales57.7%
KevinProc7.8%
JudySales29.2%
JuliusSales62.9%
BrettProc92.3%
TomOP17.1%
GiseleSales69.6%
KatieSales76.4%
HilaryProc36.1%
DonOP91.1%
LucySales69.3%
DaniProc64.1%
ThomasSales27.5%
KateSales79.8%
KevinProc63.3%
JudySales17.9%
JuliusSales13.1%
BrettProc42.1%
TomOP90.7%
GiseleSales46.6%
KatieSales86.6%
HilaryProc28.9%
DonOP7.6%
LucySales39.1%

I'd like to add a new colum that shows the average Margin depending on the person's Position. After that I'd like to make a visualization that shows the avergage margin by name in columns and as constant horizontal lines the average margin by position. Is it possible to do this? Thank you very much for your support

Capture.PNG

2 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

hola @AldoMF

 

Replace All with AllSelected

 

 




Lima - Peru

View solution in original post

Vvelarde
Community Champion
Community Champion

@AldoMF

 

Maybe exist another solution  more easy but try with:

 

 

AVG-Margin-Proc = CALCULATE([Avg-margin],FILTER(ALLEXCEPT(Persons,Persons[Year],Persons[Quarter],Persons[Category],Persons[Country],Persons[Group]),Persons[Position]="Proc"))

modified the other measures like this with AllExcept

 

And Position in a slicer..Don't put in visual level filter.




Lima - Peru

View solution in original post

9 REPLIES 9
Vvelarde
Community Champion
Community Champion

hi @AldoMF

 

is possible to do.

 

first: Create a measure to obtain the average margin:

 

Avg-margin = AVERAGE(Persons[Margin])

next create a measure for each Position

 

AVG-Margin-OP =
CALCULATE ( [Avg-margin], FILTER ( ALL ( Persons ), Persons[Position] = "OP" ) )
AVG-Margin-Sales =
CALCULATE (
    [Avg-margin],
    FILTER ( ALL ( Persons ), Persons[Position] = "Sales" )
)
AVG-Margin-Proc =
CALCULATE (
    [Avg-margin],
    FILTER ( ALL ( Persons ), Persons[Position] = "Proc" )
)

Finally in a line clustered column chart visual put the columns and measure in this way:

 

look.png




Lima - Peru

Hi @Vvelarde Thank you very much for your answer it worked perfect, however I made a mistake by not including all of the information. My data also contains Months, Years, Quarters, Category and Country, something like this:

 

NamePositionMarginMonthYearQuarterGroupGroupCategoryCountry
DaniProc9.2%Oct-15154 OneAEurope
ThomasSales62.4%Nov-15154 twoBNorth America
KateSales57.7%Dec-15154 OneDAsia
KevinProc7.8%Jan-16161 twoTSouth America
JudySales29.2%Feb-16161 OneHOceania
JuliusSales62.9%Mar-16161 twoAAfrica

 

When I used your solution, it showed me the total Margin average, but once I started playing with the visualizations and filtering the visualizations by country, year, quarter, etc. the lines didn't change their value. Is there a way in which I can have those same lines but they change their value as I filter the visualization? My visualization looks something like this:

Untitled.png

 

 Is there a way to make the values of the lines change as I filter the report?

Once again thank you for your help and support! You're awesome!

 

Hello from Guadalajara, Mexico 🙂

Vvelarde
Community Champion
Community Champion

hola @AldoMF

 

Replace All with AllSelected

 

 




Lima - Peru

Hi @Vvelarde Thank you very much!

 

Eres un crack

AldoMF
Frequent Visitor

Hi @Vvelarde What if I just want to show in the Colums the people with Position "PC" but I need the three lines to still show in the graphs?

Vvelarde
Community Champion
Community Champion

@AldoMF

 

In visual level filter of the chart drag Position and Select the position.




Lima - Peru

@Vvelarde I've done so and the other two lines dissapear because of the "ALLSelected" filter

Vvelarde
Community Champion
Community Champion

@AldoMF

 

Maybe exist another solution  more easy but try with:

 

 

AVG-Margin-Proc = CALCULATE([Avg-margin],FILTER(ALLEXCEPT(Persons,Persons[Year],Persons[Quarter],Persons[Category],Persons[Country],Persons[Group]),Persons[Position]="Proc"))

modified the other measures like this with AllExcept

 

And Position in a slicer..Don't put in visual level filter.




Lima - Peru

Thanks @Vvelarde! It worked perfectly!

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!

December 2024

A Year in Review - December 2024

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