Forum Discussion

freemainia's avatar
freemainia
Helper I
3 years ago
Solved

Add column whose value depends on two other columns

I have a column called ID and another called Status. 

 

I want to create a new column called NEW COL.

 

If Status = "Yes" for any of the rows with the same ID then the NEW COL = "Yes" for those rows, else

If Status = "Partial" for any of the rows with the same ID then the NEW COL = "Partial" for those rows, else

If Status = "No" for any of the rows with the same ID then the NEW COL = "No" for those rows.

 

IDStatusNEW COL
1YesYes
1NoYes
1NoYes
2PartialYes
2YesYes
2NoYes
3NoPartial
3PartialPartial
3NoPartial
3NoPartial
4NoNo
4 No
4NoNo
4NoNo

 

So essentially, a "Yes" overides "Partial" and "No"; "Partial" overides "No"; everything else is "No".

 

  • freemainia 

    Give this a try.

    New Status = 
    VAR _Yes = CALCULATE(COUNTROWS(VALUES('Table'[ID])),'Table'[Status]="Yes",ALLEXCEPT('Table','Table'[ID]))
    VAR _Partial = CALCULATE(COUNTROWS(VALUES('Table'[ID])),'Table'[Status]="Partial",ALLEXCEPT('Table','Table'[ID]))
    RETURN 
    SWITCH(
        TRUE(),
        _Yes > 0, "Yes",
        _Partial > 0, "Partial",
        "No"
    )

6 Replies

  • freemainia 

    Give this a try.

    New Status = 
    VAR _Yes = CALCULATE(COUNTROWS(VALUES('Table'[ID])),'Table'[Status]="Yes",ALLEXCEPT('Table','Table'[ID]))
    VAR _Partial = CALCULATE(COUNTROWS(VALUES('Table'[ID])),'Table'[Status]="Partial",ALLEXCEPT('Table','Table'[ID]))
    RETURN 
    SWITCH(
        TRUE(),
        _Yes > 0, "Yes",
        _Partial > 0, "Partial",
        "No"
    )
  • That is how you would do it as a calculated column.  You would just put that DAX in as the new column on the table.