Forum Discussion
Calculated Measure with conditions
- Anonymous9 years ago
jaymanivannan response is great. To add to this, rather than using the / symbol and have to make a divide by zero check, just use the Divide() function. I've also set this out using a spacing format, which is a good habit to get yourself into.
Here is an updateSalesAverage = DIVIDE( CALCULATE( SUM(Total Sales $), [AccountCode]=410000 ), CALCULATE ( Sum(Total Sales Quantity), [AccountCode]=420000 ) )
Hi,
You should use the CALCULATE function.
Your formula should look something like this:
SalesAverage:= CALCULATE (SUM(Total Sales $), [AccountCode]=410000) / CALCULATE (Sum(Total Sales Quantity), [AccountCode]=420000).
I would also add division by zero condition check
Michael
- Anonymous9 years agoNot applicable
jaymanivannan response is great. To add to this, rather than using the / symbol and have to make a divide by zero check, just use the Divide() function. I've also set this out using a spacing format, which is a good habit to get yourself into.
Here is an updateSalesAverage = DIVIDE( CALCULATE( SUM(Total Sales $), [AccountCode]=410000 ), CALCULATE ( Sum(Total Sales Quantity), [AccountCode]=420000 ) )- jaymanivannan9 years agoFrequent Visitor
Anonymous, This is working !!!. Thanks for the quick response. No Zero divide error. Thank you once again.
- Anonymous9 years agoNot applicable
I want to thank Anonymous too. He did a lot of the work.
- abhi17078 years agoNew Member
AnonymousAnonymousWhat if i want to apply where condition on categorical variable, say account status= Yes or No, want to calculate for those accounts whose status is No. Pls advise.
- Anonymous8 years agoNot applicable
It's similar, depends on a datatype of your categorical variable.
If it's string then just use smth like: CALCULATE(SUM([Amount]),Account_Status="No")
or this:
CALCULATE(SUM(Fact_Table[Amount]),Filter(Accounts,Accounts[Account_Status]="No"))
in case you have two connected tables
Michael