Forum Discussion

nshindel's avatar
nshindel
Frequent Visitor
4 years ago
Solved

Previous Moth to Date for same dates as current month

I am looking to create a measure based that looks at a total from the previous month, based on the current date.   So, if today is June 17th, I would like the measure to show May 1st-16th. I have t...
  • nshindel's avatar
    4 years ago

    Figured this out for anyone interested

    Attribute MTD Previous Month = 
    var yesterday = TODAY()-1
    
    var currentmonth = MONTH(yesterday)
    var currentyear = YEAR(yesterday)
    var currentday = DAY(yesterday)
    
    var priormonth = if(currentmonth = 1,12, currentmonth - 1)
    var totalvalue = sum('Adobe - Master Overall Pivot'[Value])
    
    RETURN CALCULATE(SUM('table'[Value]),DateTable[DayOfMonth] <= currentday,DateTable[MonthNumberOfYear]=priormonth,DateTable[Year]=currentyear)