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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
freemainia
Helper I
Helper I

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

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

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

View solution in original post

6 REPLIES 6
jdbuchanan71
Super User
Super User

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.

So good. Thanks @jdbuchanan71 . 

jdbuchanan71
Super User
Super User

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

Hey @jdbuchanan71 , thanks again for your solution.

As an add-on to the above, how could I have this column (or measure) respond to a slicer.

I posted this question here:

Add column whose value depends on two other column... - Microsoft Power BI Community

Thanks mate. Is there a way to do this as a calculated column too, as I wanted to chuck the result in a pie chart?

Hi,

This calculated column formula works

=if(CALCULATE(COUNTROWS(Data),FILTER(data,Data[ID]=EARLIER(Data[ID])&&Data[Status]="Yes"))>0,"Yes",if(CALCULATE(COUNTROWS(Data),FILTER(data,Data[ID]=EARLIER(Data[ID])&&Data[Status]="Partial"))>0,"Partial","No"))

Hope this helps.

Untitled.png


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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.