Reply
kayjenki
Regular Visitor

New Column Based on Value from Two Existing Columns

I am trying to create a new column that takes into consideration values from two existing columns, the first column is a unique ID that is repeated multiple times and the second column is either a Yes or No value associated to the unique ID.

 

I want the new column to state "Yes" if a yes (column B) exist at any point for the rows associated to the unique ID (column A) and "No" if there are not any rows associated to the unique ID that state yes. Below is an example, I was having a hard time articulating this, hopefully, it makes sense.

 

Unique IDValueNew Column
AAAA1234NoYes
AAAA1234NoYes
AAAA1234NoYes
AAAA1234YesYes
BBBB1234NoNo
BBBB1234NoNo
BBBB1234NoNo
BBBB1234NoNo
CCCC1234YesYes
CCCC1234NoYes
CCCC1234NoYes
CCCC1234NoYes
1 ACCEPTED SOLUTION
quantumudit
Super User
Super User

Hello @kayjenki 
Thank you for providing sample data.

To achieve the desired result, you can use the following formula to create a calculated column:

 

New Column - Calculated =
VAR _id = 'Table'[Unique ID]
VAR _values =
    DISTINCT (
        SELECTCOLUMNS (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Unique ID] = _id
            ),
            [Value]
        )
    )
VAR _containsYesCount =
    COUNTROWS (
        FILTER (_values, CONTAINSSTRING ([Value], "Yes"))
    )
RETURN
    IF (_containsYesCount = 1, "Yes", "No")

Below is the screenshot of the result, allowing you to effortlessly compare the expected outcomes with the calculated ones:

quantumudit_0-1738873532847.png

 

I am also attachig the Power BI for your reference.

 

Best Regards,
Udit

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
Visit My Linktree: LinkTree

Proud to be a SuperUser

View solution in original post

3 REPLIES 3
quantumudit
Super User
Super User

Hello @kayjenki 
Thank you for providing sample data.

To achieve the desired result, you can use the following formula to create a calculated column:

 

New Column - Calculated =
VAR _id = 'Table'[Unique ID]
VAR _values =
    DISTINCT (
        SELECTCOLUMNS (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Unique ID] = _id
            ),
            [Value]
        )
    )
VAR _containsYesCount =
    COUNTROWS (
        FILTER (_values, CONTAINSSTRING ([Value], "Yes"))
    )
RETURN
    IF (_containsYesCount = 1, "Yes", "No")

Below is the screenshot of the result, allowing you to effortlessly compare the expected outcomes with the calculated ones:

quantumudit_0-1738873532847.png

 

I am also attachig the Power BI for your reference.

 

Best Regards,
Udit

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
Visit My Linktree: LinkTree

Proud to be a SuperUser

Thank you, that worked perfect.

Happy to help 😊

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)