Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Issues with Month[today]

I have a formula:

6month Prior = CALCULATE(SUM('Sales Data'[sales_price]),  FILTER('Sales Data','Sales Data'[Month Match] = true && 'Sales Data'[Month if Matching] = [Current Month]-6))/ CALCULATE([# of WorkDays], FILTER('Date Key', 'Date Key'[Month] = [Current Month] -6))

However, this returns blank and its due to my [Current Month] measure. This measure is 
Current Month = MONTH(TODAY()).

This will allow me to go back to 5 months prior, but will not at 6 months and I think it is due to the fact it will bleed into 2023, which is what I need. I am not sure to fix this.

 




  • Anonymous I would recommend using EOMONTH. You can use a pattern such as:

    Measure =
      VAR __Today = TODAY()
      VAR __Max = EOMONTH( __Today, -6 )
      VAR __Min = DATE( YEAR( __EOM6 ), MONTH( __EOM6 ), 1 )
      VAR __Table = FILTER( ALL( 'Sales Data' ), [Date] >= __Min && [Date] <= __Max )
      VAR __Result = SUMX( __Table, [sales price] )
    RETURN
      __Result

    Or do you not have a Date column?

14 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Anonymous I would recommend using EOMONTH. You can use a pattern such as:

    Measure =
      VAR __Today = TODAY()
      VAR __Max = EOMONTH( __Today, -6 )
      VAR __Min = DATE( YEAR( __EOM6 ), MONTH( __EOM6 ), 1 )
      VAR __Table = FILTER( ALL( 'Sales Data' ), [Date] >= __Min && [Date] <= __Max )
      VAR __Result = SUMX( __Table, [sales price] )
    RETURN
      __Result

    Or do you not have a Date column?

  • Anonymous's avatar
    Anonymous
    Not applicable

    I just figured it out, but still need help with a solution. 

    6month Prior = CALCULATE(SUM('Sales Data'[sales_price]),  FILTER('Sales Data','Sales Data'[Month Match] = true && 'Sales Data'[Month if Matching] = [Current Month]-6))/ CALCULATE([# of WorkDays]FILTER('Date Key''Date Key'[Month] = [Current Month] -6))

    it works except for 6+ months prior because we are in June (month 6) -6 is 0. But I need to now go back to 12/2023. Any ideas are appreciated!!

  • Anonymous Perhaps use a month offset column which has a 0 for the current month and adds/subtracts 1 for every month forward/back

    • Anonymous's avatar
      Anonymous
      Not applicable

      Could you send me an example?

      • michaelu1's avatar
        michaelu1
        Advocate II

        I use this in power Query:

        #"Added Custom1" = Table.AddColumn(#"Inserted Quarter", "Month Offset", each (([Year]-Date.Year(Today))*12)
        +([Month]-Date.Month(Today))),