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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Ozcoz
Frequent Visitor

2 columns contain x, then y - Custom column

Hi there,

 

I've looked in the forums and can't find a solution to my simple issue.

 

The table has 2 columns 'Season' and 'Endorsed_season' and I'm looking for discrepancies in the two fields. 

Ozcoz_2-1699229884322.png

Return 'Valid' if both columns contain the word 'spring', or they both contain 'autumn'.

Otherwise, return 'Invalid'.

In the above image, the result should be: Invalid for row 1, then Valid for row 2.

 

The following code returns an error:

Ozcoz_3-1699230305951.png

 

Season_valid =
IF(
(CONTAINS(all_burn[Season], "Spring") & CONTAINS(all_burn[Endorsed_Season], "Spring")),
"Valid",
IF(
(CONTAINS(all_burn[Season], "Autumn") & CONTAINS(all_burn[Endorsed_Season], "Autumn")),
"Valid",
"Invalid"
)
)

 

I also tried creating a column from examples, but it wasn't smart enough to work it out the pattern.

 

Thanks.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Ozcoz ,

You can use the following DAX to create a new column:

Valid_Invalid = 
IF(
    CONTAINSSTRING('Table'[Season], "SPRING") && CONTAINSSTRING('Table'[Endorsed_season], "SPRING") ||
    CONTAINSSTRING('Table'[Season], "AUTUMN") && CONTAINSSTRING('Table'[Endorsed_season], "AUTUMN"),
    "Valid",
    "Invalid"
)

And the final output is shown in the following figure:

vjunyantmsft_0-1699250924655.png

Best Regards,

Dino Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Ozcoz ,

You can use the following DAX to create a new column:

Valid_Invalid = 
IF(
    CONTAINSSTRING('Table'[Season], "SPRING") && CONTAINSSTRING('Table'[Endorsed_season], "SPRING") ||
    CONTAINSSTRING('Table'[Season], "AUTUMN") && CONTAINSSTRING('Table'[Endorsed_season], "AUTUMN"),
    "Valid",
    "Invalid"
)

And the final output is shown in the following figure:

vjunyantmsft_0-1699250924655.png

Best Regards,

Dino Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

VahidDM
Super User
Super User

Hey 

Please try these 2:
Custom column in PQ:
= Table.AddColumn(#"Changed Type", "Custom", each if (Text.Contains([SEASON], "Spring") or Text.Contains([SEASON], "Autumn"))
and (Text.Contains([ENDORSED_SEASON], "Spring") or Text.Contains([ENDORSED_SEASON], "Autumn"))
then "Valid"
else "Invalid")

 

and this one as the custom column 1:
= Table.AddColumn(#"Added Custom", "Custom.1", each if (Text.Contains([SEASON], "Spring") and Text.Contains([ENDORSED_SEASON], "Spring")) or (Text.Contains([SEASON], "Autumn") and Text.Contains([ENDORSED_SEASON], "Autumn"))
then "Valid"
else "Invalid")

the output:

VahidDM_0-1699232933431.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

 

Ozcoz
Frequent Visitor

Thanks for your reply.

 

Can you clarify, are these 2 different ways to reutrn the result, or are they both required?

 

I created a custom for both of these options in PQ editor, but they both show table.

Ozcoz_1-1699236271133.png

 

When I click on table, they both return a column of Invalid only. 

Ozcoz_2-1699236708220.png

I'm not super adept with PowerBI, am I doing something wrong?

Sorry for that 🙂
Use this as custom column:
= Table.AddColumn(Source, "Custom", each if ((Text.Contains([SEASON], "Spring") and Text.Contains([ENDORSED_SEASON], "Spring")) or (Text.Contains([SEASON], "Autumn") and Text.Contains([ENDORSED_SEASON], "Autumn")))
then "Valid"
else "Invalid")

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

Ozcoz
Frequent Visitor

Sorry, but it still returns 'Table'.

Ozcoz_0-1699248235400.png

Clicking on it returns an error on all rows and it removes the headers, essentially making each column Column 1, Column 2 as headings.

 

Clicking on the error says:

Expression.Error: The field 'SEASON' of the record wasn't found. But this is likely due to the lack of headings.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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