I have 3 columns sales, profit, quantity and I am calculating two measure sales_per_unit and profit_per_unit:
Profit_Per_Unit = DIVIDE(SUM(Orders[Profit]), SUM(Orders[Quantity]))
Sales_Per_Unit = DIVIDE(SUM(Orders[Sales]), SUM(Orders[Quantity]))
I am getting correct answer for all rows but grand total is wrong as you can see in below screenshot:
So I want to understand two things:
- why this is happening
- what is the solution
EDIT
by using Sales_Per_Unit2 = SUMX(Orders, DIVIDE(Orders[Sales],Orders[Quantity])) it gives me grand total as expected but getting wrong answer for some of the rows as highlighted in below image
UPDATE
i have searched internet and people are using HASONEVALUE function in if condition to filterout different formula for true context and different formula for false context so i also used that formula combined with @MarcoVos answer and i got blank result for the rows where i am getting wrong result but i still not understood full scenario that what is wrong am i doing but i got some clue that formula is right but there is some thing wrong with row context so i thought to update in my question.
If_Sales = IF(HASONEVALUE(Orders[Sales]),SUMX(Orders, DIVIDE(Orders[Sales], Orders[Quantity])))



Sales_Per_Unit3 = IF ( COUNTROWS('Orders') > 1, ">1 row" , SUMX( 'Orders', DIVIDE( Orders[Sales], Orders[Quantity] ) ) )- Marco Vos