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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Anonymous
Not applicable

Dax Max of 3 Columns and Average if all years selected

Hello Power BI Community, I am new. If someone could please help me.


I have 3 columns, I want to be able to sum the columns and for the formula to return to max of the 3 columns in table below return me the highlighted yellow number. And if I select all years on the filter for it to find the average, but if I select the year it return the max of all 3 columns. 

 

So for example if I have a table that is filtered by 2022 returns 22, if it is filtered by 2023 it returns 23, and if there is no filter it returns the average of 22 and 23 22.5.

 

Alisia_D_0-1711051768268.png

This code provides me with the max of the 3 columns (that I turned into a measure), but it totals the years when I want it to average the years example the diagram 22.5 not 45.

MaxOfThreeMeasures =
VAR MaxValue = MAX ( Measure1, Measure2 )
RETURN
MAXX ( VALUES ( Table ), MAXX ( VALUES ( Table ), MAXX ( VALUES ( Table ), MAX ( MaxValue, Measure3 ) ) ) )

Anyone able to help please?

1 ACCEPTED SOLUTION
Dangar332
Super User
Super User

Hi, @Anonymous 

 

try below code for measure

 

Measure 2 = 
var a_s = SUM(alisia[Column1])
var b_s = SUM(alisia[Column2])
var c_s = SUM(alisia[Column3])
var a_v = AVERAGEX(alisia,CALCULATE(SUM(alisia[Column1]),ALLEXCEPT(alisia,alisia[year])))
var b_v = AVERAGEX(alisia,CALCULATE(SUM(alisia[Column2]),ALLEXCEPT(alisia,alisia[year])))
var c_v = AVERAGEX(alisia,CALCULATE(SUM(alisia[Column3]),ALLEXCEPT(alisia,alisia[year])))
var sum_ =MAX(MAX(a_s,b_s),c_s)
var avg_ = MAX(MAX(a_v,b_v),c_v)
RETURN
IF(ISFILTERED(alisia[year]),sum_,avg_)

 

 

Dangar332_0-1711055474470.png

 

Dangar332_1-1711055483912.png

 

if any year not selected then like below

Dangar332_2-1711055494371.png

 

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

4 REPLIES 4
Dangar332
Super User
Super User

Hi, @Anonymous 

 

try below code for measure

 

Measure 2 = 
var a_s = SUM(alisia[Column1])
var b_s = SUM(alisia[Column2])
var c_s = SUM(alisia[Column3])
var a_v = AVERAGEX(alisia,CALCULATE(SUM(alisia[Column1]),ALLEXCEPT(alisia,alisia[year])))
var b_v = AVERAGEX(alisia,CALCULATE(SUM(alisia[Column2]),ALLEXCEPT(alisia,alisia[year])))
var c_v = AVERAGEX(alisia,CALCULATE(SUM(alisia[Column3]),ALLEXCEPT(alisia,alisia[year])))
var sum_ =MAX(MAX(a_s,b_s),c_s)
var avg_ = MAX(MAX(a_v,b_v),c_v)
RETURN
IF(ISFILTERED(alisia[year]),sum_,avg_)

 

 

Dangar332_0-1711055474470.png

 

Dangar332_1-1711055483912.png

 

if any year not selected then like below

Dangar332_2-1711055494371.png

 

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

Anonymous
Not applicable

Hi @Dangar332  THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!

gmsamborn
Super User
Super User

Hi @Anonymous 

 

I would like to help but I'm a little unclear about your requirements.

 

Can you provide the following?

 

1)  Please provide sample data that covers your issue or question completely.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

 

2) Please show the expected outcome based on the sample data you provided.
https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

 

 

A .pbix file with sample data would be best.



Proud to be a Super User!

daxformatter.com makes life EASIER!
Anonymous
Not applicable

Hi @gmsamborn , I am unable to past a link but I can provide screenshots hopefully they can clarify.

Here is the data set:

Alisia_D_3-1711055112572.png

 

Here is the card, which is saying 45.0 but I want it to say 22.5 and average not sum when its on select all (2022 + 2023)

Alisia_D_0-1711054910856.png


If I click on a year its correct because I want it to sum the 3 columns and provide me the max. The sum is 22 for 2022.

Alisia_D_1-1711054978798.png

And 23 for 2023

Alisia_D_2-1711055046252.png

So the sum is 45 which its giving now, but I want it to give me 22.5 the average of the two.






Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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