Search code examples
powerbidax

Dax time intelligents function for semester equivalent to DATESYTD()


Need to calculate The Semester to date just like the functions

 1. DATESMTD()
 2. DATESQTD()
 3. DATESYTD()

This function does not exist. How can I create a dax measure that does this for a semester?


Solution

  • Semester_to_date = 
    VAR MaxDate = VAR MaxDate = MAX('Calendar Lookup'[Date])    -- Variable to get the max date
    VAR MinDate =                                               -- Variable to get the min date for the semester
    IF(
        MONTH(MAX('Calendar Lookup'[Date]))<=6,                 -- if month <= then 6
        DATE(YEAR(MAX('Calendar Lookup'[Date])),1,1),           -- then max date = first day of january (month 1)
        DATE(YEAR(MAX('Calendar Lookup'[Date])),7,1)            -- else max date = first day of july (month 7)
    )
    
    RETURN
    CALCULATE(
        [Your Measure] or expression,                           -- Measure or expression you would like to analyse
        DATESBETWEEN('Calendar Lookup'[Date],MinDate,MaxDate)   -- Check between variables MinDate and MaxDate
    )