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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Contain DAX, can any1 tell what's wrong with it?

any1 know what's wrong with this DAX? 

 

Source = if(CONTAINS('Category-DataFlagType','Category-DataFlagType'[Type],"A"),"A",if(contains('Category-DataFlagType','Category-DataFlagType'[Type],"B"),"B",if(contains('Category-DataFlagType','Category-DataFlagType'[Type],"C"),"C",if(CONTAINS('Category-DataFlagType','Category-DataFlagType'[Type],"M"),"M","Other"))))

1 ACCEPTED SOLUTION

Hi @Anonymous

 

How about this version?

 

Source = SWITCH (
                TRUE(),
                FIND("A",'Category-DataFlagType'[Type],,0)>0,"A1",
                FIND("B",'Category-DataFlagType'[Type],,0)>0,"B1",
                FIND("C",'Category-DataFlagType'[Type],,0)>0,"C1",
                FIND("M",'Category-DataFlagType'[Type],,0)>0,"M1",
                ---- ELSE -----
                "OTHER")

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

You could try this approach

 

Source = IF(
            'Category-DataFlagType'[Type] IN (
                                         {"A","B","C","M"}
                                            ),
              'Category-DataFlagType'[Type],
              "Other"
              ) 

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

@Phil_Seamark sorry, i maybe misleading, i actually want if value contain "A", then "A1", if value contain "B", then, "B1"....else "Other"

 

thanks

 

Hi @Anonymous

 

How about this version?

 

Source = SWITCH (
                TRUE(),
                FIND("A",'Category-DataFlagType'[Type],,0)>0,"A1",
                FIND("B",'Category-DataFlagType'[Type],,0)>0,"B1",
                FIND("C",'Category-DataFlagType'[Type],,0)>0,"C1",
                FIND("M",'Category-DataFlagType'[Type],,0)>0,"M1",
                ---- ELSE -----
                "OTHER")

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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