Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe 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.
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?
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?
@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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
25 | |
12 | |
9 | |
9 | |
9 |
User | Count |
---|---|
21 | |
14 | |
14 | |
13 | |
13 |