2

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,

enter image description here

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,

enter image description here

Asad Hussain
  • 564
  • 2
  • 15
  • Please show us the results They produced. I prefer to keep my answer secret till I see it. Then I will share what I know. – Ozan Sen Nov 08 '22 at 15:40
  • @OzanSen Sorry for the late response. I have added the results of both the measures in Screenshots. If you would like to further investigate, you can also download the Power BI Workbook from the link given in the post. I would really appreciate to know your answer on this. I am still new to Power BI so solving these type of confusions can go a long way. – Asad Hussain Nov 09 '22 at 12:36
  • Thank you for the results table. I had the chance to check the file, and there are a couple points I didn't quite explain to myself. So I don't want to convey a wrong information to you! When my full analysis is finished, I will gladly share! For now, Stay safe! – Ozan Sen Nov 14 '22 at 07:07
  • @OzanSen Anything you found, if possible please do share. Thank you. – Asad Hussain Jan 22 '23 at 08:16

0 Answers0