The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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
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.
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"
)
Hi,
you just need to replace else with comma "," otherwise it will be same for the dax
User | Count |
---|---|
28 | |
11 | |
8 | |
6 | |
5 |
User | Count |
---|---|
35 | |
14 | |
12 | |
9 | |
7 |