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
Power_BI_Adapt
Resolver I
Resolver I

IF ELSE in measure using DAX

Dear All,

 

I have the folllwing situation:

 

I want to create a measure showing the result of two types of margins. Depending on the type of product, a certain margin percentage applies. I have simplyfied the sitution below:

 

Power_BI_Adapt_1-1655977390650.png

 

The result should be a measure (in red) and is making use of a margin scheme which can be hardcoded in DAX. The margin scheme isn't a separate table,; it's just published to show the margin percentages used.

 

I am think to make use of a IF ELSE forumlua within DAX. Any other suggestion / solution is welcome.

 

Thanks!

 

 

 

 

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@Power_BI_Adapt create this caclulated column:

 

Result = 
'Table'[price] * IF('Table'[Type = "Normal", 0.1, 0.2)

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

5 REPLIES 5
SpartaBI
Community Champion
Community Champion

@Power_BI_Adapt create this caclulated column:

 

Result = 
'Table'[price] * IF('Table'[Type = "Normal", 0.1, 0.2)

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Thanks again for your prossible solution.

 

However, when I run this formula, I get the message that I need to aggregate with Minimum, Maximum, Nummber of Sum function on field 'Table[Type]'. How can I solve this?

 

Thanks!

@Power_BI_Adapt hey, just to make sure, cause I missed a columm bracket there, you tried:
Result =
'Table'[price] * IF('Table'[Type] = "Normal", 0.1, 0.2)
And you got that message?
That means you try to create a visaul and not a calculated column.
Try:
Result =
SUMX(
'Table',
'Table'[price] * IF('Table'[Type] = "Normal", 0.1, 0.2)
)


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Thanks a lot for this additional suggestion.

 

However when I use this forumla, I still get a message that column / field  [Type]  in table 'Table'  cannot be found, but this field is a field / column in table 'Table'.

 

Thanks for any additional suggestion

@Power_BI_Adapt hey, will PM you now

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.