Forum Discussion

jcastr02's avatar
jcastr02
Icon for Post Prodigy rankPost Prodigy
1 year ago
Solved

Average on or after a specific date

I have a file with store closing dates and daily sales....

I'd like to be able to see the average of the Daily Sales column only for data ON or AFTER the closure date.  Example for store 123, the Average of those 6 Dates is ~297, but for those 5 dates after 1/2/2025, the average is 305 =  (257+300+301+333+332)/ 5

Is there a measure that can do this?

See below sample data

DateStr NumberDaily SalesClosure DateAvg After Closing Date
1/1/20251232561/2/2025 
1/2/20251232571/2/2025305
1/3/20251233001/2/2025 
1/4/20251233011/2/2025 
1/5/20251233331/2/2025 
1/6/20251233321/2/2025 
1/1/20254561001/3/2025 
1/2/20254561011/3/2025 
1/3/20254561251/3/2025113
1/4/20254561101/3/2025 
1/5/20254561111/3/2025 
1/6/20254561051/3/2025 
1/1/20257895011/4/2025 
1/2/20257895251/4/2025 
1/3/20257895651/4/2025 
1/4/20257895251/4/2025529
1/5/20257895301/4/2025 
1/6/20257895311/4/2025 
1/1/20251017001/5/2025 
1/2/20251017051/5/2025 
1/3/20251017021/5/2025 
1/4/20251017011/5/2025 
1/5/20251016941/5/2025687
1/6/20251016801/5/2025 
1/1/20251021001/6/2025 
1/2/20251021081/6/2025 
1/3/20251021071/6/2025 
1/4/20251021061/6/2025 
1/5/20251021051/6/2025 
1/6/20251021151/6/2025115
  • jcastr02,

     

    Try this measure:

     

    Avg After Closing Date = 
    VAR vTable =
        CALCULATETABLE (
            SUMMARIZE ( 'Table', 'Table'[Str Number], 'Table'[Daily Sales] ),
            'Table'[Date] >= 'Table'[Closure Date]
        )
    VAR vResult =
        AVERAGEX ( vTable, 'Table'[Daily Sales] )
    RETURN
        vResult

     

     

  • jcastr02,

     

    Try adding an additional filter to exclude blank dates:

     

    Avg After Closing Date =
    VAR vTable =
        CALCULATETABLE (
            SUMMARIZE ( 'Table', 'Table'[Str Number], 'Table'[Daily Sales] ),
            'Table'[Date] >= 'Table'[Closure Date],
            NOT ISBLANK ( 'Table'[Closure Date] )
        )
    VAR vResult =
        AVERAGEX ( vTable, 'Table'[Daily Sales] )
    RETURN
        vResult

     

4 Replies

  • jcastr02,

     

    Try this measure:

     

    Avg After Closing Date = 
    VAR vTable =
        CALCULATETABLE (
            SUMMARIZE ( 'Table', 'Table'[Str Number], 'Table'[Daily Sales] ),
            'Table'[Date] >= 'Table'[Closure Date]
        )
    VAR vResult =
        AVERAGEX ( vTable, 'Table'[Daily Sales] )
    RETURN
        vResult

     

     

    • jcastr02's avatar
      jcastr02
      Icon for Post Prodigy rankPost Prodigy

      Thank you DataInsights 

      Would you know also how to exclude dates where the Closure date field is blank.  It seems when there is no closing date listed its pulling those values in.  Thanks for your help. 

      • DataInsights's avatar
        DataInsights
        Icon for Super User rankSuper User

        jcastr02,

         

        Try adding an additional filter to exclude blank dates:

         

        Avg After Closing Date =
        VAR vTable =
            CALCULATETABLE (
                SUMMARIZE ( 'Table', 'Table'[Str Number], 'Table'[Daily Sales] ),
                'Table'[Date] >= 'Table'[Closure Date],
                NOT ISBLANK ( 'Table'[Closure Date] )
            )
        VAR vResult =
            AVERAGEX ( vTable, 'Table'[Daily Sales] )
        RETURN
            vResult