Forum Discussion

viitama's avatar
viitama
Frequent Visitor
8 years ago
Solved

Create column based on other columns

Hi,

 

I have following table and would like to recreate res column.

 

idtimevalres
A11212
A2912
A31512
B12424
B22224
B327

24

 

 

res column whould value from val column which equals minimum time column. What is easiest way to achieve this? This should be done for each id as a group.

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    8 years ago

    viitama

     

    If Min time can be other than 1, then this column

     

    Res =
    VAR Mintime =
        CALCULATE ( MIN ( TableName[time] ), ALLEXCEPT ( TableName, TableName[id] ) )
    RETURN
        CALCULATE (
            MIN ( TableName[val] ),
            FILTER ( ALLEXCEPT ( TableName, TableName[id] ), TableName[time] = Mintime )
        )

4 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    viitama

     

    If Min time is always 1, then you can use

     

    Res =
    CALCULATE (
        MIN ( TableName[val] ),
        FILTER ( ALLEXCEPT ( TableName, TableName[id] ), TableName[time] = 1 )
    )
    • Zubair_Muhammad's avatar
      Zubair_Muhammad
      Community Champion

      viitama

       

      If Min time can be other than 1, then this column

       

      Res =
      VAR Mintime =
          CALCULATE ( MIN ( TableName[time] ), ALLEXCEPT ( TableName, TableName[id] ) )
      RETURN
          CALCULATE (
              MIN ( TableName[val] ),
              FILTER ( ALLEXCEPT ( TableName, TableName[id] ), TableName[time] = Mintime )
          )
    • viitama's avatar
      viitama
      Frequent Visitor

      Thanks. What about if Val column is text? What can be used instead of minimum to get that text to new column. This is just extra but would like to know.