Forum Discussion

POSPOS's avatar
POSPOS
Post Partisan
2 years ago
Solved

Conditional columns using DAX in Power BI

HI All,

I have a requirement to display a new column based on a two other columns from the same table.

 

Scenario:

For each contract no., look for the minimum 'contract received date' and then display the respective 'contract executed date' in the new column.

 

Sample data:

Contract No.Contract Received dateContract Executed DateNew Column

22

7/7/20224/17/20234/17/2023

22

7/7/20224/17/20234/17/2023

22

8/7/20221/11/20224/17/2023

22

8/7/20221/11/20224/17/2023
2311/4/20237/8/20214/6/2021
2311/4/20237/8/2021 4/6/2021
232/9/20234/6/2021 4/6/2021
232/9/20234/6/2021 4/6/2021
245/8/20211/1/20211/1/2021
245/8/20211/1/20211/1/2021
249/9/20232/2/20221/1/2021
249/9/20232/2/20221/1/2021

 

Could someone please help with the DAX to achieve this result?

 

Thank you

  • and you can try this

    DateNew2 = 
    VAR t1 = 'Table'[Contract No.]
    VAR t2 = ALLEXCEPT( 'Table', 'Table'[Contract No.] )
    VAR t3 = CALCULATE( MIN( 'Table'[Contract Received date] ),t2  )
    RETURN 
        CALCULATE(MIN('Table'[Contract Executed Date]),t2,
            'Table'[Contract No.] = t1 && 'Table'[Contract Received date] = t3
        )

5 Replies

  • pls try this

    DateNew = 
    VAR t1 = 'Table'[Contract No.]
    VAR t2 = CALCULATE( MIN( 'Table'[Contract Received date] ), ALLEXCEPT( 'Table', 'Table'[Contract No.] ) )
    RETURN
        MINX(
            FILTER( ALL( 'Table' ), 'Table'[Contract No.] = t1 && 'Table'[Contract Received date] = t2 ),
            'Table'[Contract Executed Date]
        )

  • and you can try this

    DateNew2 = 
    VAR t1 = 'Table'[Contract No.]
    VAR t2 = ALLEXCEPT( 'Table', 'Table'[Contract No.] )
    VAR t3 = CALCULATE( MIN( 'Table'[Contract Received date] ),t2  )
    RETURN 
        CALCULATE(MIN('Table'[Contract Executed Date]),t2,
            'Table'[Contract No.] = t1 && 'Table'[Contract Received date] = t3
        )
    • Ahmedx's avatar
      Ahmedx
      Super User

      sorry you can shorten the code further try this

       

      DateNew2 = 
      VAR t1 = 'Table'[Contract No.]
      VAR t2 = ALLEXCEPT( 'Table', 'Table'[Contract No.] )
      VAR t3 = CALCULATE( MIN( 'Table'[Contract Received date] ),t2  )
      RETURN 
          CALCULATE(
              MIN('Table'[Contract Executed Date]),t2,
               'Table'[Contract Received date] = t3
          )

       

      • POSPOS's avatar
        POSPOS
        Post Partisan

        This worked too! thank you for the solution