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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
JrBIAnalyst
Frequent Visitor

Max of four values in a measure

This falls under the heading of "It works, but surely there's a better way to do this."

Background: I have a measure using LINEST to project results based on current data. I want to calculate and display the upper and lower bound of the LINEST as error bars. You can interpret the results of LINEST as y = (Slope1 +/- StandardErrorSlope1) * x + (Intercept +/- StandardErrorIntercept) which provides a range of values bounding the result of the LINEST expression. That means there are four possible expressions (++, +-, -+, and --) that could return the bounding values of y.

 

In DAX terms, that looks like this.

CPI-U Linest UB = 
VAR line =
    LINESTX (
        CalculateTable(CPI, AND(CPI[Month] >= SELECTEDVALUE('Reference Month'[Month]), CPI[DateType] = "current")),
        CPI[CPI-U],
        CPI[Month]
    )
VAR m = SELECTCOLUMNS ( line, [Slope1] )
VAR em = SELECTCOLUMNS ( line, [StandardErrorSlope1] )
VAR b = SELECTCOLUMNS ( line, [Intercept] )
VAR eb = SELECTCOLUMNS ( line, [StandardErrorIntercept] )
VAR x = SELECTEDVALUE ( CPI[Month] )
VAR ypp = (m + em) * x + (b + eb)
VAR ypm = (m + em) * x + (b - eb)
VAR ymp = (m - em) * x + (b + eb)
VAR ymm = (m - em) * x + (b - eb)
RETURN Max(Max(Max(ypp,ypm),ymp),ymm)


My question relates to that last line, RETURN Max(Max(Max(ypp,ypm),ymp),ymm). Surely, there's a better way to return the Max of four variables... right?

2 REPLIES 2
JrBIAnalyst
Frequent Visitor

Thanks, @BeaBF.

 

I had looked at something like that and concluded that constructing the tempTable felt more complicated than nesting maxes. How would you go about creating that tempTable?

BeaBF
Super User
Super User

@JrBIAnalyst Hi!
In my opinion, instead of nesting multiple MAX functions, you can use the MAXX function in combination with VALUES to iterate over the four variables and find the maximum value:
RETURN MAXX(VALUES("TempTable"[TempColumn]), [Variable])

BBF

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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