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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.