Sum(If(InYear(OrderDate, Today(), -1), Sales))

InYear, InMonth and period flags in Power BI

Qlik developers often put InYear() and InMonth() flags in the script (-1 or 0) and multiply by them in charts, or use them inside If(). In Power BI, the equivalent is a calendar table with offset columns (YearOffset, MonthOffset), filtered with CALCULATE or a relative-date slicer. Time-intelligence functions such as SAMEPERIODLASTYEAR cover the common cases.

Partial / different approach DAX Model

Short answer: Add Year Offset = YEAR('Date'[Date]) - YEAR(TODAY()) to the calendar. Then Sales LY = CALCULATE([Sales], 'Date'[Year Offset] = -1). Or, relative to the selection, CALCULATE([Sales], SAMEPERIODLASTYEAR('Date'[Date])).

What it does in Qlik

  • InYear(timestamp, base_date, period_no [, first_month_of_year]) returns True (-1) if the timestamp is in the year containing base_date, shifted by period_no.
  • InQuarter, InMonth, InWeek and InDay work the same way. The ...ToDate variants (InYearToDate) stop at base_date.
  • first_month_of_year handles fiscal years.

Qlik example

Qlik script and chart
// script flags in the calendar
-InYear(Date, Today(), 0)  AS IsCurrentYear,
-InYear(Date, Today(), -1) AS IsLastYear,
-InMonth(Date, Today(), -1) AS IsLastMonth
// chart
Sum(Sales * IsLastYear)
Sum(If(InYear(OrderDate, Today(), -1, 4), Sales))   // fiscal year from April

Power BI equivalent

Calendar offset columns

DAX
Year Offset  = YEAR ( 'Date'[Date] ) - YEAR ( TODAY () )
Month Offset =
    ( YEAR ( 'Date'[Date] ) - YEAR ( TODAY () ) ) * 12
    + MONTH ( 'Date'[Date] ) - MONTH ( TODAY () )
Fiscal Year = YEAR ( EDATE ( 'Date'[Date], -3 ) )     // FY starts in April, labelled by start year

Measures

DAX
Sales last year (calendar) = CALCULATE ( [Sales], 'Date'[Year Offset] = -1 )
Sales last month           = CALCULATE ( [Sales], 'Date'[Month Offset] = -1 )

// relative to whatever the user selected, not to today
Sales SPLY = CALCULATE ( [Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )

Gotchas and behaviour differences

  • Calculated columns are computed at refresh, so offsets based on TODAY() are only as fresh as the last refresh. That's the same as script flags in Qlik. If you need "today" at query time, compare against TODAY() inside the measure instead.
  • Filtering 'Date'[Year Offset] = -1 replaces any user filter on Year Offset, but keeps filters on other date columns such as Month. If a Month slicer is active, wrap it as CALCULATE([Sales], 'Date'[Year Offset] = -1, REMOVEFILTERS('Date')). That clears every date filter, like {<Year=, Month=, Date=>} in Qlik. Qlik's {<Year=>} alone would clear only Year.
  • Time-intelligence functions need a proper date table marked as one. See master calendar.

Official documentation

Related pages

Spotted an error or a better pattern? QlikToDax is maintained by a working BI consultant; corrections are welcome via the About page. Last reviewed 2026-10-25.