Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dwilltho27
Regular Visitor

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.

screenshot.PNG

Thank you a lot for your help.

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@dwilltho27 

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

Fowmy_0-1604259253528.png

 

________________________

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

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

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.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Fowmy
Super User
Super User

@dwilltho27 

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

Fowmy_0-1604259253528.png

 

________________________

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

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

FrankAT
Community Champion
Community Champion

Hi @dwilltho27 

take a look at the folowing solution:

 

01-11-_2020_18-06-45.png

 

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)

@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?

mahoneypat
Employee
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

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.