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
Anonymous
Not applicable

DAX Column value conditional on multiple rows

I have a joined table of opportunities and products grouped by product line, e.g. 

 

Opp | Product Line

A     |   X

B     |   Y

C     |   X

C     |   Y

D    |   Z

 

I'm interested in being able to filter on the Opportunities like C, where they contain two specific product lines (X and Y). All assistance appreciated.

1 ACCEPTED SOLUTION

Hi @Anonymous

 

Try this Column

 

OppContainsXandY =
VAR Mytable =
    FILTER ( TableName, TableName[Opp] = EARLIER ( TableName[Opp] ) )
RETURN
    IF (
        CONTAINS ( mytable, TableName[Product Line], "X" )
            && CONTAINS ( mytable, TableName[Product Line], "Y" ),
        "Yes",
        "No"
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

5 REPLIES 5
v-xjiin-msft
Solution Sage
Solution Sage

@Anonymous

 

If you want to filter your table, you can simply use a slicer. Please refer:

 

11.PNG22.PNG

If above sample doesn't satisfy your requirement, please kindly elaborate your requirement with detailed description and your desired result.

 

Thanks,
Xi Jin.

Anonymous
Not applicable

I'm trying to find opportunies like C... i.e. opportunities that contain both product line X and product line Y. The Opportunity column is in reality an Opp ID not a category of opportunity. Perhaps it would be clearer to say that producing a category to filter on is what i'm trying to do.

 

Opp | Product Line | OppContainsXandY

 A    |         X           |            No

 B    |         Y           |            No

C    |         X           |            Yes

C    |         Y           |            Yes

D    |         Z           |            No

E    |         Y           |            Yes

E    |         X           |            Yes

F    |         X           |            No

F    |         Z           |            No

G    |         X           |            Yes

G    |         Y           |            Yes

G    |         Z           |            Yes

 

What is the DAX to create the column OppContainsXandY?

Hi @Anonymous

 

Try this Column

 

OppContainsXandY =
VAR Mytable =
    FILTER ( TableName, TableName[Opp] = EARLIER ( TableName[Opp] ) )
RETURN
    IF (
        CONTAINS ( mytable, TableName[Product Line], "X" )
            && CONTAINS ( mytable, TableName[Product Line], "Y" ),
        "Yes",
        "No"
    )

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Hi @Zubair_Muhammad

 

Your solution works great - thank you!

@Anonymous

 

contains.png


Regards
Zubair

Please try my custom visuals

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.