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

Case Statements

Hi,

 

I was trying to implement a case statement using switch DAX and the like operator "%" but was not able to do it.

Here is the requirement

 

if sales_model = 305.5% then 305.5

if sales_model = 306.5% then 306.5

if sales_model = 307.5% then 307.5

if sales_model = D3% then D3

In all other cases take first 3 characters of sales_model

 

Sample Data:

 

Sales Model
305.5E2
306.5E2
307.5E2
912AFAF
D3E2
1 ACCEPTED SOLUTION
Gordonlilj
Solution Sage
Solution Sage

Hi,

 

Does this give you the result you need?

Column = SWITCH (
              TRUE (),
              SEARCH ( "305", 'Table'[Sales Model],, 0 ) = 1, "305.5",
              SEARCH ( "306.5", 'Table'[Sales Model],, 0 ) = 1, "306.5",
              SEARCH ( "307.5", 'Table'[Sales Model],, 0 ) = 1, "307.5",
              SEARCH ( "D3", 'Table'[Sales Model],, 0 ) = 1, "D3",
              
              LEFT('Table'[Sales Model],3)
)

View solution in original post

2 REPLIES 2
Gordonlilj
Solution Sage
Solution Sage

Hi,

 

Does this give you the result you need?

Column = SWITCH (
              TRUE (),
              SEARCH ( "305", 'Table'[Sales Model],, 0 ) = 1, "305.5",
              SEARCH ( "306.5", 'Table'[Sales Model],, 0 ) = 1, "306.5",
              SEARCH ( "307.5", 'Table'[Sales Model],, 0 ) = 1, "307.5",
              SEARCH ( "D3", 'Table'[Sales Model],, 0 ) = 1, "D3",
              
              LEFT('Table'[Sales Model],3)
)
Anonymous
Not applicable

Hi @Gordonlilj 

 

Thanks. Could you please explain why are we using =1 after every search ?

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.