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
daveedd
Helper II
Helper II

Min/Max of a list of variables

Hi all,

 

QQ.  I have a bunch of calculations which end in a list of variables sat with some values, eg

var madeupvar1 = 4

var madeupvar2 = 30

var madeupvar3 = 35

var madeupvar4 = 100

var madeupvar5 = 32

 

(of course there's a calculation to get to the value, but that's not important to the question)

 

All I'm looking to do is drop off the top and bottom values as outliers to make some averaging more reliable.  I can't use max or min as they're not in a column.  I put them into a single var and can use topn to get the largest, but I cannot get the smallest value.

Any ideas?

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @daveedd 

There are probably a few ways you could do this.

They would all involve constructing a single-column table containing the variable values.

 

Here are a couple of options (using either MINX/MAXX or TOPN), with VarListTrimmed containing the reduced list of values, to use as required:

VAR madeupvar1 = 4
VAR madeupvar2 = 30
VAR madeupvar3 = 35
VAR madeupvar4 = 100
VAR madeupvar5 = 32
VAR VarList = { madeupvar1, madeupvar2, madeupvar3, madeupvar4, madeupvar5 }
VAR VarMin =
    MINX ( VarList, [Value] )
VAR VarMax =
    MAXX ( VarList, [Value] )
VAR ValuesToRemove = { VarMin, VarMax }
VAR VarListTrimmed =
    EXCEPT ( VarList, ValuesToRemove )

 

VAR madeupvar1 = 4
VAR madeupvar2 = 30
VAR madeupvar3 = 35
VAR madeupvar4 = 100
VAR madeupvar5 = 32
VAR VarList = { madeupvar1, madeupvar2, madeupvar3, madeupvar4, madeupvar5 }
VAR VarMin =
    TOPN ( 1, VarList, [Value], ASC )
VAR VarMax =
    TOPN ( 1, VarList, [Value], DESC )
VAR ValuesToRemove =
    UNION ( VarMin, VarMax )
VAR VarListTrimmed =
    EXCEPT ( VarList, ValuesToRemove )

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

4 REPLIES 4
OwenAuger
Super User
Super User

Hi @daveedd 

There are probably a few ways you could do this.

They would all involve constructing a single-column table containing the variable values.

 

Here are a couple of options (using either MINX/MAXX or TOPN), with VarListTrimmed containing the reduced list of values, to use as required:

VAR madeupvar1 = 4
VAR madeupvar2 = 30
VAR madeupvar3 = 35
VAR madeupvar4 = 100
VAR madeupvar5 = 32
VAR VarList = { madeupvar1, madeupvar2, madeupvar3, madeupvar4, madeupvar5 }
VAR VarMin =
    MINX ( VarList, [Value] )
VAR VarMax =
    MAXX ( VarList, [Value] )
VAR ValuesToRemove = { VarMin, VarMax }
VAR VarListTrimmed =
    EXCEPT ( VarList, ValuesToRemove )

 

VAR madeupvar1 = 4
VAR madeupvar2 = 30
VAR madeupvar3 = 35
VAR madeupvar4 = 100
VAR madeupvar5 = 32
VAR VarList = { madeupvar1, madeupvar2, madeupvar3, madeupvar4, madeupvar5 }
VAR VarMin =
    TOPN ( 1, VarList, [Value], ASC )
VAR VarMax =
    TOPN ( 1, VarList, [Value], DESC )
VAR ValuesToRemove =
    UNION ( VarMin, VarMax )
VAR VarListTrimmed =
    EXCEPT ( VarList, ValuesToRemove )

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

HI ,

I have one question, what exactly is " [Value] " part of this code ? When you refer to a list of measures you put this [Value] . I didn't find any info about this in dax.guide. 


Hi @Marcinvelcino 

When a table is created with the table constructor, the columns are named automatically.

Single column: Value

Multiple columns: Value1, Value2, ...

 

Example:

https://dax.do/XDfV48Dah5bBNo/


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Awesome thanks a lot!

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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