Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Measure Difficulties

Hi Team,    I have a simple table with 3 columns.    I have been tasked to create a measure. The client wants to see the Average sales per customer where the SalesDate falls in between the period...
  • MFelix's avatar
    MFelix
    6 years ago

    Hello @water_hydration ,

    This is related to the filter context should be after the AVERAGEX and not within AVERAGEX:

    12 Month Sales =
    VAR __startcurrentmonth =
        DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 )
    VAR __previous12 =
        EDATE ( __startcurrentmonth, -12 )
    RETURN
        CALCULATE (
            AVERAGEX ( SalesTable, AVERAGE ( SalesTable[Sales ($)] ) ),
            FILTER (
                ALL ( SalesTable ),
                SalesTable[SalesDate] <= __startcurrentmonth
                    && SalesTable[SalesDate] >= __previous12
            )
        )