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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors