Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

DAX conditional Column based on the same column value with multiple rows

Hi all,

 

I'd like to create a DAX column which returns a text value with rules.

  1. If Category = "Done", then "Good"
  2. If for the same Account value (for example A with multiple rows) Category = "Done" AND "Unfinished", then it's still "Good".
  3. If Category = "Unfinished", then "In Progress"

I tried with a SWITCH True formula, but (as expected) it didn't work, because the conditions only applies for one row after another. The rules should apply to the column Account with the same value. For example Account = A has three rows. The 3rd row in the new column "defined" should be "Good" as well, because Account A has Category = "Done" in the first two rows.

The same applies to the other marked rows.

Thank you a lot for your help.

  • Anonymous 

    Add the following code as anew column to your table:

    Defined = 
    IF( 
        ISEMPTY( FILTER( Accounts , Accounts[Account] = EARLIER(Accounts[Account]) && Accounts[Category] = "Done")),
        "In Progress",
        "Done"
    )

     

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube  LinkedIn

     



5 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    Switch True returns the first one that's true.  All you need to do is change the order.  Put the one with && as the second one.

    Regards,

    Pat

     

  • FrankAT's avatar
    FrankAT
    Community Champion

    Hi Anonymous 

    take a look at the folowing solution:

     

     

    Defined = 
    VAR _Text = CONCATENATEX(VALUES('Table'[Category]),'Table'[Category])
    RETURN
        SWITCH(TRUE(),
            _Text = "Done" , "Good",
            _Text = "Unfinished" , "In Progress",
            "Good"
        )

     

    With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
    FrankAT (Proud to be a Datanaut)

    • Anonymous's avatar
      Anonymous
      Not applicable

      mahoneypat Thx, but didn't work.

      @FrankAT

      thanks. I tried the same solution, but in my case Account C is still "Good" instead of "In Progress".

      What is different in my new column?

  • Anonymous 

    Add the following code as anew column to your table:

    Defined = 
    IF( 
        ISEMPTY( FILTER( Accounts , Accounts[Account] = EARLIER(Accounts[Account]) && Accounts[Category] = "Done")),
        "In Progress",
        "Done"
    )

     

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube  LinkedIn

     



  • Hi,

    This calculated column formula works

    =if(AND(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Account]=EARLIER(Data[Account])&&(Data[Category]="Done"||Data[Category]="Unfinished")))=CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Account]=EARLIER(Data[Account]))),CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Account]=EARLIER(Data[Account])&&Data[Category]="Done"))>=1),"Good","In progress")

    Hope this helps.