Forum Discussion

Nas211's avatar
Nas211
Regular Visitor
3 years ago
Solved

Datesbetween

Hi guys, I'm néw to writing Dax queries and I'm currently stuck trying to use the "Datesbetween" feature to write queries with multiple criteria. I'm trying to have a stacked trend lines with multipl...
  • amitchandak's avatar
    3 years ago

    Nas211 , what are trying to achieve here, Datesbetween should use date table for continuous dates (Date

     

    You need one measure

    TrendYears = CALCULATE(SUM(merged_data[Workinghours]), Datesbetween ('Date'[Date], date(2019,1,1), date(2022, 5, 25)))

     

    More examples

     

    YTD =
    var _omax = format(if(isfiltered('Date'),MAXX( allselected( 'Date') , 'Date'[Date]) , today()), "MMDD")
    var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
    var _min = if(month(_max) <4, Date(year(_max)-1,4,1) ,Date(year(_max),4,1) )
    return
    CALCULATE(calculate([net], filter('Date'), format('Date'[Date], "MMDDD") <=_omax) ,DATESBETWEEN('Date'[Date],_min,_max))

     

    YTD =
    var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
    var _min = eomonth(_max,-1*MONTH(_max))+1
    return
    CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))


    YTD =
    var _max1 = MAXX( allselected('Date'), 'Date'[Date]) )
    var _min1 = MINX( allselected('Date'), 'Date'[Date]) )
    var _max = date(Year(_max1)+1, Month(_max1), day(_max1))
    var _min = date(Year(_min1)+1, Month(_min1), day(_min1))
    return
    CALCULATE(count(salesforce_opportunity[Account Id]) ,DATESBETWEEN('Date'[Date],_min,_max))


    YTD till Last month =
    var _max = eomonth(if(isfiltered('Date'),MAX( 'Date'[Date]) , today()),-1)
    var _min = eomonth(_max,-1*MONTH(_max))+1
    return
    CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))