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
granade1
Frequent Visitor

Measure in table that considers an if statement, divide two column sums

My mult. of W2 column is working with this measure:

Mult. of W2 = (SUM(Merge2[InvoiceAmnt]) / SUM(Merge2[Cost+Exp Total])/100)

Capture.PNG
 
but I need to include an if statement for when expenses are = 0. to avoid infinity.
So something like:
if expenses = 0 then SUM(Merge2[InvoiceAmnt]) / SUM(Merge2[Cost-Time])/100
ELSE (SUM(Merge2[InvoiceAmnt]) / SUM(Merge2[Cost+Exp Total])/100)                             <-my original measure
END
Still learning DAX and can't seem to figure this out. thanks!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

First of all, mate, it's not a measure you're working with but a calculated column. The stuff you think is a measure is an in-column expression.

 

Mult. of W2 =
var __invoiceSum = SUM( Merge2[InvoiceAmnt] )
var __costMinusTimeSum = SUM( Merge2[Cost-Time] )
var __costPlusExpSum = SUM( Merge2[Cost+Exp Total] )
var __exprWhenExpensesEquals0 =
	DIVIDE ( 
		__invoiceSum,
		__costMinusTimeSum * 100
	)
var __exprWhenExpensesNotEquals0 =
	divide (
		__invoiceSum,
		__costPlusExpSum * 100
	)
var __result =
	if (
		Merge2[Expenses] = 0,
		__exprWhenExpensesEquals0,
		__exprWhenExpensesNotEquals0
	)
return
	__result

Best

Darek

View solution in original post

1 REPLY 1
Anonymous
Not applicable

First of all, mate, it's not a measure you're working with but a calculated column. The stuff you think is a measure is an in-column expression.

 

Mult. of W2 =
var __invoiceSum = SUM( Merge2[InvoiceAmnt] )
var __costMinusTimeSum = SUM( Merge2[Cost-Time] )
var __costPlusExpSum = SUM( Merge2[Cost+Exp Total] )
var __exprWhenExpensesEquals0 =
	DIVIDE ( 
		__invoiceSum,
		__costMinusTimeSum * 100
	)
var __exprWhenExpensesNotEquals0 =
	divide (
		__invoiceSum,
		__costPlusExpSum * 100
	)
var __result =
	if (
		Merge2[Expenses] = 0,
		__exprWhenExpensesEquals0,
		__exprWhenExpensesNotEquals0
	)
return
	__result

Best

Darek

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.

Top Solution Authors