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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

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
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors