Time Intelligence Functions() |Power BI || Belayet Hossain

Time Intelligence Functions() |Power BI || Belayet Hossain

Time Intelligence functions are used to analyze and compare data over different periods (e.g., year-to-date, quarter-to-date, month-to-date). Here's a detailed explanation of each Time Intelligence Function in Power BI. The explanation includes Purpose, Use, Syntax, Example, Scenario, Relevant DAX, and Comparative Differences.

?

?? 1. CALENDAR()

  • Purpose: Returns a table with a single column named "Date" that contains a contiguous set of dates. The range of dates is from the specified start date to the specified end date, inclusive of those two dates.
  • Syntax: CALENDAR(<start_date>, <end_date>)
  • Example:

Scenario: We want to create a custom date range from January 1, 2023, to December 31, 2023, for reporting purposes.

DAX: CALENDAR(DATE(2023, 1, 1), DATE(2023, 12, 31))

  • Comparative Difference:

CALENDARAUTO() automatically detects the date range from the model, while CALENDAR() requires you to manually input the start and end dates.


??2. CALENDARAUTO()

  • Purpose: Returns a table with a single column named "Date" that contains a contiguous set of dates. The range of dates is calculated automatically based on data in the model.
  • Syntax: CALENDARAUTO([fiscal_year_end_month])
  • Example:

Scenario: If our dataset contains data from 2022 to 2023, this function will create a date table from January 1, 2022, to December 31, 2023.

DAX : CALENDARAUTO()

  • Comparative Difference:

CALENDAR() requires start and end dates, while CALENDARAUTO() figures it out based on the data.


??3. DATESYTD()

  • Purpose: Returns a table that contains a column of the dates for the year to date, in the current context.
  • Syntax : DATESYTD(<dates> [,<year_end_date>])
  • Example:

Scenario: We want to analyze all cost data for the current year up to today's date.

DAX: Costs (DATESYTD) = CALCULATE([Total cost (ALL)], DATESYTD('calendar'[date]))

  • Comparative Difference: TOTALYTD() performs calculations like SUM over the year-to-date period, while DATESYTD() only returns the date table.


??4. DATESQTD()

  • Purpose: Returns a table that contains a column of the dates for the quarter to date, in the current context.
  • Syntax : DATESQTD([<dates_column>])
  • Example:

Scenario: You want to analyze the Sold Quantity data for the current quarter.

DAX: Qty Sold (DATESMTD) = CALCULATE([Total Qty], DATESQTD('calendar'[date]))

  • Comparative Difference: DATESQTD() provides quarter-specific analysis, whereas DATESYTD() works for the entire year.


??5. DATESMTD()

  • Purpose: Returns a table of dates from the start of the current month up to the last date in the current context.
  • Syntax : DATESMTD([<dates_column>])

  • Comparative Difference: Similar to DATESYTD(), but focuses on the current month rather than the year.
  • Example:

Scenario: We want to analyze the Sold Quantity data for the current month.

Here We have used DATEMTD() function to calculate the cumulative Sold quantity for the month. for that we can see after completing January month again started cumulative sum from the 1st of February Month.

Similarly DATESYTD() will cumulative sum within a year then It will start cumulative sum from the 1st of next year.

DATEQTD() will do same for Quarter wise.


??6. TOTALYTD()

  • Purpose: Evaluates the year-to-date value of the expression in the current context.
  • Syntax: TOTALYTD(<expression>, <dates_column>, [<filter>], [<year_end_date>])
  • Example:

Scenario: We want to calculate total cost up to today's date for the year.

DAX: Costs (TOTALYTD) = TOTALYTD([Total cost (ALL)], 'calendar'[date])

  • Comparative Difference: TOTALYTD() performs calculations, whereas DATESYTD() only returns the date range.


??7. TOTALQTD()

  • Purpose: Returns a table that contains a column of the dates for the quarter to date, in the current context.
  • Syntax: TOTALQTD(<expression>, <dates_column>, [<filter>])
  • Example:

Scenario: We want to calculate the total cost for the current quarter.

DAX: Costs (TOTALQTD) = TOTALQTD([Total cost (ALL)], 'calendar'[date])

  • Comparative Difference: TOTALQTD() is quarter-specific, while TOTALMTD() is month-specific.


??8. TOTALMTD()

  • Purpose: Returns a table that contains a column of the dates for the month to date, in the current context.
  • Syntax: TOTALMTD(<expression>, <dates_column>, [<filter>])

  • Comparative Difference: TOTALMTD() works for the month-to-date, while TOTALYTD() works for the year-to-date.
  • Example

Scenario: You want to calculate the total Sold Quantity for the current month.

Here We have used TOTALMTD() function to calculate the cumulative total Sold quantity for the month. for that we can see after completing January month again started cumulative sum from the 1st of February Month.

Similarly TOTALYTD() will cumulative sum within a year then It will start cumulative sum from the 1st of next year.

TOTALQTD() will do same for Quarter wise.


?? 9. DATESINPERIOD()

  • Purpose: Returns a table of dates shifted back or forward by a given interval.
  • Syntax: DATESINPERIOD(<dates_column>, <start_date>, <number_of_intervals>, <interval_type>)
  • Comparative Difference: DATEADD() shifts dates forward or backward, while DATESINPERIOD() works with a specific interval.
  • Example:

Scenario: We want to analyze each next 5 days of Costs data starting from the 1st days of data.

Here, DATESINPERIOD() used to calculate the running total of a cost over the last 5 days, ending on the current date (or the maximum date in the data context).


?? 10. PARALLELPERIOD()

  • Purpose: Returns a table that shifts the period (e.g., month, quarter, or year) forward or backward by a specified number of intervals.
  • Syntax: PARALLELPERIOD(<dates>,<number_of_intervals>,<interval>)
  • Example:

Scenario: We want to compare cost from the same period last Month.

Here, The DAX expression uses the PARALLELPERIOD() function along with CALCULATE() to compute the total costs for the previous month. (e.g., for March, it will show February’s costs).


??11. SAMEPERIODLASTYEAR()

  • Purpose: Returns a table of dates for the same period in the previous year.
  • Syntax: SAMEPERIODLASTYEAR(<dates_column>)
  • Example:

Scenario: We want to compare this year’s sales to the same period last year.


?? 12. DATEADD()

  • Purpose: Shifts the dates in a table forward or backward by a specific interval.
  • Syntax: DATEADD(<dates_column>, <number_of_intervals>, <interval_type>)
  • Example: We want to compare cost data for a previous day.

Here, This DAX formula is calculating with DATEADD () function the total cost for the previous day based on the current context of dates


??Comparative Difference:


#powerbi #timeintelligence #functions #powerbideveloper

要查看或添加评论,请登录

Belayet Hossain ??的更多文章

社区洞察

其他会员也浏览了