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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
derekmalag
New Member

Calculated Colum: Get MIN value from a filtered table

Hi, I'm stuck in something that I think it is simple but I can't make it work so I'm pretty sure I'm doing something incorrectly but don;t know what so would appreciatte any light on it.

 

I have a Table with two columns and I want to create a calculated column that get the Min value of the Model. The expected output is 

ModelTotal_ValueMIN_VALUE
A3 *3
A43
B52
B2*2
C97
A63
C7*7
B82

 

So I've tried the following DAX query for the calculated column

 

MIN_VALUE = CALCULATE (
     MIN('MyTable'[Total_Value]),
     FILTER('MyTable',[Model]=[Model])
)

 

 However, what I get is the minimum value of the table without being filtered (2 for all values).

 

I would appreciate any help on what I am doing wrong.

 

Many thanks in advance

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@derekmalag Here are a couple different ways:

MIN_VALUE = 
CALCULATE (
     MIN('MyTable'[Total_Value]),
     FILTER('MyTable',[Model]=EARLIER('MyTable'[Model]))
)

MIN_VALUE = 
  VAR __Model = [Model]
RETURN
  CALCULATE (
     MIN('MyTable'[Total_Value]),
     FILTER('MyTable',[Model]=__Model)
  )


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Here is the simple one line solution:

shwetadalal_0-1638614475944.png

Min_Value = CALCULATE(MIN('Table'[Total Value]),FILTER('Table',EARLIER('Table'[Model])='Table'[Model]))
HotChilli
Super User
Super User

@Greg_Deckler did I just catch you using a "CALCULATE"? 

 

can't we rely on anything any more?....

@HotChilli Ha! Good one. I was actually going to include a version using MINX but figured it was overkill. Was easier just to correct the version of the formula that used CALCULATE since it was already there.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@derekmalag Here are a couple different ways:

MIN_VALUE = 
CALCULATE (
     MIN('MyTable'[Total_Value]),
     FILTER('MyTable',[Model]=EARLIER('MyTable'[Model]))
)

MIN_VALUE = 
  VAR __Model = [Model]
RETURN
  CALCULATE (
     MIN('MyTable'[Total_Value]),
     FILTER('MyTable',[Model]=__Model)
  )


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

amazing @Greg_Deckler , I've used the [EARLIER] option and it works so not going through the second :). Assuming not, but just to be sure, if there is any consideration in performance between these two options?

 

Many thanks again 

@derekmalag If you're concerned about performance, then you should filter on columns rather than tables whenever possible.

 

I'd probably write it like this instead:

MIN_VALUE =
CALCULATE (
    MIN ( 'MyTable'[Total_Value] ),
    ALLEXCEPT ( 'MyTable', 'MyTable'[Model] )
)

@derekmalag In my testing, no I have not seen a performance difference between the two approaches. You might be interested in this: In Defense of EARLIER - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors