Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Writing out expression gives different result than inserting the measure that is exactly the same?

Hey guys i'm learning dax. I wrote this measure on training data= 

Average Quantity Sold per Day = AVERAGEX(VALUES(Dates[Date]);[Total Quantity Sold])
When I drag this expression in the visualisation canvas, I get the result 26,03. So far, so good.
Now here's the weird thing. The second argument, [Total Quantity Sold], is written like this (i'm just copypasting my measures here)=
Total Quantity Sold = SUM(Sales[Quantity])
I wanted to replace my measure reference in the averagex measure by the full written expression instead of the measure name to better help me understand what is happening, so I wrote:
Average Quantity Sold per Day = AVERAGEX(VALUES(Dates[Date]);SUM(Sales[Quantity]))
Now after pressing enter, my visualisation (which just gives the value in a one row, one column table i.e. I just the 'table' visualisation to check my result) gives 9528,00?? Either i'm missing something simple or I do not understand DAX behavior at all. The second Average Quantity Sold per Day expression is just the first one with the name for my measure written as an expression, so how is it giving different results? 
 
Thanks in advance!
 
 
 
  • hi Anonymous 

    Since Total Quantity Sold = SUM(Sales[Quantity])

    In the Measure [Average Quantity Sold per Day], It nested a measure [Total Quantity Sold].

    Average Quantity Sold per Day = AVERAGEX(VALUES(Dates[Date]);[Total Quantity Sold]) ,

    So it essentially looks like this formula 

    Average Quantity Sold per Day=AVERAGEX(VALUES('Date'[Date]); CALCULATE(SUM(Sales[Quantity])) )

    not this formula Average Quantity Sold per Day = AVERAGEX(VALUES(Dates[Date]);SUM(Sales[Quantity]))

     

    Please refer to CALCULATE Function in dax

    https://docs.microsoft.com/en-us/dax/calculate-function-dax

     

    Regards,

    Lin

1 Reply

  • v-lili6-msft's avatar
    v-lili6-msft
    Icon for Community Support rankCommunity Support

    hi Anonymous 

    Since Total Quantity Sold = SUM(Sales[Quantity])

    In the Measure [Average Quantity Sold per Day], It nested a measure [Total Quantity Sold].

    Average Quantity Sold per Day = AVERAGEX(VALUES(Dates[Date]);[Total Quantity Sold]) ,

    So it essentially looks like this formula 

    Average Quantity Sold per Day=AVERAGEX(VALUES('Date'[Date]); CALCULATE(SUM(Sales[Quantity])) )

    not this formula Average Quantity Sold per Day = AVERAGEX(VALUES(Dates[Date]);SUM(Sales[Quantity]))

     

    Please refer to CALCULATE Function in dax

    https://docs.microsoft.com/en-us/dax/calculate-function-dax

     

    Regards,

    Lin