I have the following two DAX Commands, who seem to be giving different results,
First DAX command
FourLeggedSales = SUMX(
FILTER(Purchase, RELATED('Product'[Legs]) = 4),
Purchase[Quantity]
)
Second DAX Command,
FourLeggedSales = CALCULATE( SUM(Purchase[Quantity]), 'Product'[Legs] = 4)
The second DAX Command is given in the solution file and apparently gives correct results. While the first one was what I wrote and it is giving wrong results.
Can anyone help me understand what's causing the issue here?
Additional Information if Needed
Just to be clear, I am solving this problem of DAX here: https://www.wiseowl.co.uk/power-bi/exercises/dax/filtering/4094/
You can find the Example Workbook from the link provided as well (with the dataset)
^These are the two example DAX Commands I gave here.
Complete DAX Measure that I created is as given (it doesn't give correct results)
Ratio =
var FourLeggedSales = SUMX(
FILTER(Purchase, RELATED('Product'[Legs]) = 4),
Purchase[Quantity]
)
var SixLeggedSales = SUMX(
FILTER(Purchase, RELATED('Product'[Legs]) = 6),
Purchase[Quantity]
)
var SumOfSales = FourLeggedSales + SixLeggedSales
var ManyLeggedRatio = DIVIDE(SUMX(Purchase,Purchase[Quantity]), SumOfSales, 0)
Return ManyLeggedRatio
The result of the measure I created is as given,
The Measure created in the Solution File is as below,
FourLeggedRatio =
VAR SalesFourLegs = CALCULATE( SUM(Purchase[Quantity]), 'Product'[Legs] = 4)
VAR SalesSixLegs = CALCULATE( SUM(Purchase[Quantity]), 'Product'[Legs] = 6)
VAR ManyLeggedRatio = DIVIDE(SUM(Purchase[Quantity]) , (SalesFourLegs + SalesSixLegs))
RETURN ManyLeggedRatio
Result of the Measure in the Solution File is as given,