Forum Discussion

Pedro77000's avatar
Pedro77000
Frequent Visitor
6 years ago
Solved

Calculate an average with date filter

Hi Everyone,   I have a problem of averaging according to a context. I have a data model with a fact table and a "Date" dimension table Indeed, I want to calculate the average based on the mont...
  • v-frfei-msft's avatar
    6 years ago

    Hi Pedro77000 ,

     

    We can create a measure as below.

    Measure =
    VAR SUMA =
        CALCULATE (
            SUM ( 'Table'[value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[date] <= MAX ( 'date'[Date] ) )
        )
    VAR COUNTM =
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[YearMOnth] ),
            FILTER ( ALL ( 'Table' ), 'Table'[date] <= MAX ( 'date'[Date] ) )
        )
    RETURN
        DIVIDE ( SUMA, COUNTM )
    

     

    Also you can find the pbix as attached.

     

  • v-frfei-msft's avatar
    v-frfei-msft
    6 years ago

    Hi Pedro77000 ,

     

    To use ALLEXCEPT instead of ALL should work.

     

    FILTER ( ALLEXCEPT ( 'Table','Table'[region] ), 'Table'[date] <= MAX ( 'date'[Date] ) )

     

    If it doesn't meet your requirement,  Kindly share your sample data and excepted result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.