Forum Discussion

derekmalag's avatar
derekmalag
New Member
4 years ago
Solved

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

 

  • 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)
      )
    
    

7 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    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)
      )
    
    
  • Anonymous's avatar
    Anonymous
    Not applicable

    Here is the simple one line solution:

    Min_Value = CALCULATE(MIN('Table'[Total Value]),FILTER('Table',EARLIER('Table'[Model])='Table'[Model]))
    • Greg_Deckler's avatar
      Greg_Deckler
      Icon for Community Champion rankCommunity Champion

      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.