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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
pprasadravi
Helper I
Helper I

Question on calculated column

Hi,

I have a table contans customerId, Code columns. I want to add calculated column and populate either ture or false.

 

The condition is if any customer contains code C or D, then i need to add value true for all records associated to that customerId else false.

Below is the sample data. you will see false for all records  for customer id 102 as no C or D code records for 102.

 

Could you please help me to resolve the issue?

 

pprasadravi_0-1648567267310.png

 

1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @pprasadravi ,

You could create a new column like the below:

Column =
IF (
    CONTAINS (
        FILTER ( Customer, Customer[CustomerID] = EARLIER ( Customer[CustomerID] ) ),
        Customer[Code], "C"
    )
        = TRUE ()
        || CONTAINS (
            FILTER ( Customer, Customer[CustomerID] = EARLIER ( Customer[CustomerID] ) ),
            Customer[Code], "D"
        )
            = TRUE (),
    TRUE (),
    FALSE ()
)

Output result:

vluwangmsft_0-1648802307043.png

 

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

View solution in original post

4 REPLIES 4
v-luwang-msft
Community Support
Community Support

Hi @pprasadravi ,

You could create a new column like the below:

Column =
IF (
    CONTAINS (
        FILTER ( Customer, Customer[CustomerID] = EARLIER ( Customer[CustomerID] ) ),
        Customer[Code], "C"
    )
        = TRUE ()
        || CONTAINS (
            FILTER ( Customer, Customer[CustomerID] = EARLIER ( Customer[CustomerID] ) ),
            Customer[Code], "D"
        )
            = TRUE (),
    TRUE (),
    FALSE ()
)

Output result:

vluwangmsft_0-1648802307043.png

 

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

pprasadravi
Helper I
Helper I

Hi, 

Thak you for the quick response.

I want to have true or false for all rows for a  customer ID. That means I have to update false for all records realed to 102 and update true for all records related to 100 and 101 as they have C or D records.
 

I think i am able to resolve the issue using below DAX. But i am not sure this is the efficient way or not.

Contains C Or D =
VAR payeeId = 'Table'[CustomerId]

var result = CALCULATE(
Max('Table'[CustomerId]),
'Table'[Code] IN {"C", "D"}
&& 'Table'[CustomerId] = payeeId
)

return IF(result = BLANK(), FALSE(), TRUE())
mh2587
Super User
Super User

IF(Code == "C" || Code == "D" ,"True","False")


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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