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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Sarah_Sunaina
Regular Visitor

Convert Simple Conditional statement to DAX query.

Hi,

 

I'm unable to convert the below simple logic to DAX statement. Please help me out.

 

IF

Source   = 'A'  and Category  like 'FG%' then  'FG'

elseif Source   = 'B'  and Category  like RM%' then 'RM'

elseif Source   = 'C'  and Category  like 'WIP%' then 'WIP'

else 'Others'

end

 

Thanks in Advance

Sarah

3 REPLIES 3
Adamboer
Responsive Resident
Responsive Resident

ou can use the following DAX statement to replicate the logic you have described:

= IF(AND(Table1[Source]="A", LEFT(Table1[Category],2)="FG"), "FG", IF(AND(Table1[Source]="B", LEFT(Table1[Category],2)="RM"), "RM", IF(AND(Table1[Source]="C", LEFT(Table1[Category],3)="WIP"), "WIP", "Others")))

Here, we are using the IF function in DAX to replicate the conditions in your logic. The LEFT function is used to get the first two or three characters of the Category column, as per your conditions.

Note that you will need to replace "Table1" with the name of your actual table, and "Source" and "Category" with the names of the actual columns in your table.

tamerj1
Super User
Super User

Hi @Sarah_Sunaina 
Please try

Column2 =
SWITCH (
    TRUE (),
    'Table'[Source] = "A"
        && CONTAINSSTRING ( 'Table'[Category], "FG" ), "FG",
    'Table'[Source] = "B"
        && CONTAINSSTRING ( 'Table'[Category], "RM" ), "RM",
    'Table'[Source] = "C"
        && CONTAINSSTRING ( 'Table'[Category], "WIP" ), "WIP",
    "Others"
)
Anonymous
Not applicable

Hi,
you just need to replace else with comma "," otherwise it will be same for the dax

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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