{"id":86343,"date":"2020-02-14T14:43:51","date_gmt":"2020-02-14T14:43:51","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=86343"},"modified":"2022-04-24T21:39:29","modified_gmt":"2022-04-24T21:39:29","slug":"creating-time-intelligence-functions-in-dax","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/bi-sql-server\/creating-time-intelligence-functions-in-dax\/","title":{"rendered":"Creating Time-Intelligence Functions in DAX"},"content":{"rendered":"<p><strong>The series so far:<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/creating-calculated-columns-using-dax\/\">Creating Calculated Columns Using DAX<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/creating-measures-using-dax\/\">Creating Measures Using DAX<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-the-dax-calculate-and-values-functions\/\">Using the DAX Calculate and Values Functions<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-the-filter-function-in-dax\/\">Using the FILTER Function in DAX<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/cracking-dax-the-earlier-and-rankx-functions\/\">Cracking DAX\u00a0\u2013 the EARLIER and RANKX Functions<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-calendars-and-dates-in-power-bi\/\">Using Calendars and Dates in Power BI<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/creating-time-intelligence-functions-in-dax\/\"><span>Creating Time-Intelligence Functions in DAX<\/span><\/a><\/li>\n<\/ol>\n\n<p>Want to compare this year\u2019s sales with the same period in the previous year? Chart year-to-date costs? Or perhaps you want to create a twelve-month moving average of profitability? In the last article in this series, you\u2019ll learn how to use the time-intelligence functions built into DAX and understand why they work.<\/p>\n<h2>Loading the Sample Data for this Article<\/h2>\n<p>To work through the examples in this article, you\u2019ll need to download the worksheets from <a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/Time-intelligence-functions-data.xlsx\">this workbook<\/a>. Tick the following worksheets to load data from this workbook into a new Power BI report:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"369\" height=\"398\" class=\"wp-image-86344\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-17.png\" \/><\/p>\n<p>Now create a relationship between the <em>Calendar<\/em> and <em>Sales<\/em> tables by the <em>SalesDate<\/em> column, as follows (note that initially the <em>Balance<\/em> and <em>Weight<\/em> tables aren\u2019t linked to any others):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"834\" height=\"475\" class=\"wp-image-86345\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-18.png\" \/><\/p>\n<p>NOTE: This article assumes that you are only concerned with the date when sales are made. If you wanted to be able to choose between the sales date and the payment date when analysing data, you\u2019d either have to create multiple versions of the <em>Calendar<\/em> table or multiple relationships, as described in the <a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-calendars-and-dates-in-power-bi\/\">previous article<\/a> in this series.<\/p>\n<p>Finally, switch to the Modeling ribbon and choose to sort the month name by the month number:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"339\" class=\"wp-image-86346\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-19.png\" \/><\/p>\n<p>And make the <em>YearNumber<\/em> a text column:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"627\" height=\"304\" class=\"wp-image-86347\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-20.png\" \/><\/p>\n<p>Again, the reason for both of these changes is covered in the <a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-calendars-and-dates-in-power-bi\/\">previous article<\/a> in this series.<\/p>\n<h2>Creating a Draft Matrix<\/h2>\n<p>To accommodate all the wonderful measures that you\u2019re going to bring into being, create a matrix visual to show total amount sold by year and month:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"228\" height=\"381\" class=\"wp-image-86348\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-21.png\" \/><\/p>\n<p>I think it\u2019ll be easier to work with if you have all 12 months appearing, so choose to show months even when they have no corresponding data:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"467\" height=\"479\" class=\"wp-image-86349\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-22.png\" \/><\/p>\n<p>Here\u2019s what the start of the matrix should look like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"179\" height=\"367\" class=\"wp-image-86350\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-23.png\" \/><\/p>\n<p>I\u2019ve decided to hide the row subtotals for the matrix. To turn these off, go to the formatting tab and look under the Subtotals section for Row subtotals.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"278\" height=\"369\" class=\"wp-image-86351\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-24.png\" \/><\/p>\n<p>If for any reason you don\u2019t get the +\/- icons to expand\/collapse rows, enable this setting in the matrix\u2019s formatting properties:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"226\" height=\"1075\" class=\"wp-image-86352\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-25.png\" \/><\/p>\n<h2>How Time-intelligence Functions Work<\/h2>\n<p>To begin with, create a new measure on the Sales table to show total sales to date for each year (don\u2019t worry too much yet about how this works):<\/p>\n<pre class=\"lang:c# theme:vs2012\">Year-to-date = CALCULATE(\r\n    SUM(Sales[Amount]),\r\n    DATESYTD('Calendar'[DateKey])\r\n)<\/pre>\n<p>I\u2019ll come back to the <code>DATESYTD<\/code> function in more detail later in this article, but for the moment I want to use it as an example to explain how any DAX time-intelligence function is calculated. Here\u2019s what this measure should show for the matrix:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"252\" height=\"363\" class=\"wp-image-86353\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-26.png\" \/><\/p>\n<p>What I want to do is to focus on one figure \u2013 the year-to-date sales for March 2018. Start by looking at the sales amount for March 2018, which is 4.50:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"265\" height=\"141\" class=\"wp-image-86354\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-27.png\" \/><\/p>\n<p>The filter context for this figure is all of the dates in March 2018:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"106\" height=\"646\" class=\"wp-image-86355\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-28.png\" \/><\/p>\n<p>There\u2019s only one sale in March 2018, so that\u2019s why you get 4.50 as the sales for the cell:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"304\" height=\"126\" class=\"wp-image-86356\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-29.png\" \/><\/p>\n<p>By contrast, the measure to calculate year-to-date sales first destroys the existing filter context for the sales date. Without any additional change, you would get the same figure for each month:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"330\" height=\"141\" class=\"wp-image-86357\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-30.png\" \/><\/p>\n<p>However, the measure then replaces the filter context with one which picks out all of the dates from the calendar table which are on or before 31<sup>st<\/sup> March in 2018:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Year-to-date = CALCULATE(\r\n    SUM(Sales[Amount]),\r\n    DATESYTD('Calendar'[DateKey])\r\n)<\/pre>\n<p>The filter context is now as follows for the cell:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"274\" height=\"646\" class=\"wp-image-86358\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-31.png\" \/><\/p>\n<p>Power BI knows when days, months, quarters, and years start and end (they\u2019re called time-intelligence functions for a reason!). Curiously, Power BI doesn\u2019t know about weeks, so if you want to do weekly reporting, you\u2019ll have to create new aggregator columns yourself in your calendar table (again, the <a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-calendars-and-dates-in-power-bi\/\">previous article<\/a> in this series gives a guide for how to do this sort of thing).<\/p>\n<p>Here are the sales figures for the start of 2018:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"337\" height=\"171\" class=\"wp-image-86359\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-32.png\" \/><\/p>\n<p>Adding 9.49 and 4.5 gives the year-to-date figure of 13.99! This is what every time-intelligence function does: it destroys the previous filter context for each value in a visual\u2019s underlying data and replaces it with a different one according to the combination of DAX functions you\u2019ve chosen.<\/p>\n<h2>Period to Date Functions<\/h2>\n<p>Now to take a look in detail now at how to do specific things, beginning with calculating yearly, quarterly or monthly cumulative figures. You can do this using one of these functions:<\/p>\n<ul>\n<li><code>DATESYTD<\/code> or <code>TOTALYTD<\/code> (year-to-date)<\/li>\n<li><code>DATESQTD<\/code> or <code>TOTALQTD<\/code> (quarter-to-date)<\/li>\n<li><code>DATESMTD<\/code> or <code>TOTALMTD<\/code> (month-to-date)<\/li>\n<\/ul>\n<p>This functionality is typical of time-intelligence functions in DAX: there are often two or three ways to do the same thing, and which one you use is a matter of personal preference. Here\u2019s a function giving the year-to-date figures using <code>DATESYTD<\/code> shown earlier:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Year-to-date = CALCULATE(\r\n    \/\/ you could use a different aggregation function\r\n    SUM(Sales[Amount]),\r\n    \/\/ calculate over the dates for the year-to-date\r\n    DATESYTD('Calendar'[DateKey])\r\n)<\/pre>\n<p>Here\u2019s a function to do exactly the same thing using <code>TOTALYTD<\/code>:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Year-to-date 2 = TOTALYTD(\r\n    \/\/ again, we could use MAX, MIN, COUNT, etc. here\r\n    SUM(Sales[Amount]),\r\n    'Calendar'[DateKey]\r\n)<\/pre>\n<p>These two measures should give the same figures because they are, after all, doing exactly the same thing:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"329\" height=\"381\" class=\"wp-image-86360\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-33.png\" \/><\/p>\n<p>I prefer the first measure since it\u2019s clearer what it\u2019s doing (destroying the existing filter context, and replacing it with one which uses the dates for the current year up to and including the last day in the current period). The second measure using <code>TOTALYTD<\/code> is just a convenient shorthand for this.<\/p>\n<h2>Coping with Different Financial Year-ends<\/h2>\n<p>Not everyone\u2019s financial years end conveniently on 31<sup>st<\/sup> December, so you can specify a second argument for the <code>DATESYTD<\/code> function, giving your year-end date in the format <code>DD-MM<\/code>:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"473\" height=\"128\" class=\"wp-image-86361\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-34.png\" \/><\/p>\n<p>As an example, suppose that your year ends on 31<sup>st<\/sup> March. Then you could use this measure:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Year-to-date = CALCULATE(\r\n    \/\/ you could use a different aggregation function\r\n    SUM(Sales[Amount]),\r\n    \/\/ calculate over the dates for the year-to-date,\r\n    \/\/ but with year ending on 31st March\r\n    DATESYTD('Calendar'[DateKey],\"31-03\")   \r\n)<\/pre>\n<p>This measure would give this report (the box shows how the figures from 1<sup>st<\/sup> April 2018 to 31<sup>st<\/sup> March 2019 are calculated):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"437\" class=\"wp-image-86362\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-35.png\" \/><\/p>\n<p>This result would look much better if you created a new aggregator column to give the financial year and reported by that. An idea of how to do this is shown in the <a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/using-calendars-and-dates-in-power-bi\/\">previous article<\/a> in this series. Since I\u2019m feeling charitable, here is the formula that you could use to create a new calculated column in your <em>Calendar<\/em> table for the financial year:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Financial year = IF(\r\n    [MonthNumber] &lt;= 3,\r\n    \/\/ for dates up to and the end of March\r\n    [YearNumber] - 1 &amp; \"-\" &amp; [YearNumber],\r\n    \/\/ for dates from April to December\r\n    [YearNumber] &amp; \"-\" &amp; [YearNumber] + 1\r\n)<\/pre>\n<p>You\u2019ll also need a formula to determine how to sort months, so that April comes first and March last:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Financial month sort order = IF(\r\n    [MonthNumber] &lt;= 3,\r\n    \/\/ for dates up to and the end of March\r\n    [MonthNumber]+12,\r\n    \/\/ for dates from April to December\r\n    [MonthNumber]\r\n)<\/pre>\n<p>You can then choose to sort your months by the <em>Financial<\/em> <em>month<\/em> <em>sort<\/em> <em>order<\/em> column you\u2019ve created:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"532\" height=\"439\" class=\"wp-image-86363\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-36.png\" \/><\/p>\n<p>If you then display the financial year column you\u2019ve created in your matrix instead of the year, like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"237\" height=\"410\" class=\"wp-image-86364\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-37.png\" \/><\/p>\n<p>You should now get something a lot less confusing:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"238\" height=\"423\" class=\"wp-image-86365\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-38.png\" \/><\/p>\n<p>This may seem like a lot of faff, but remember that you\u2019ll only have to set up the calculated columns in your calendar once and once only.<\/p>\n<p>Finally, on the subject of changing your year-end dates, I\u2019ve only shown so far how to change the financial year-end using the <code>DATESYTD<\/code> function. The process for the <code>TOTALYTD<\/code> function is similar, but there is a catch. Here\u2019s the syntax:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"118\" class=\"wp-image-86366\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-39.png\" \/><\/p>\n<p>So it looks for all the world as if the argument to set a new year-end date is the fourth one, and that if you\u2019re not setting any additional filter, you will need to find some way to omit the third argument. However, this measure works:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Year-to-date 2 = TOTALYTD(\r\n    \/\/ again, we could use MAX, MIN, COUNT, etc. here\r\n    SUM(Sales[Amount]),\r\n    'Calendar'[DateKey],\r\n    \/\/ change the year-end date\r\n    \"03-31\"\r\n)<\/pre>\n<p>Somehow Power BI works out that you\u2019ve missed out the third <code>Filter<\/code> argument. In every other Microsoft product I\u2019ve used, you need to use a comma placeholder to show that you\u2019re omitting an argument to a function, but if you try to do this in the formula above you get an error!<\/p>\n<p>If you\u2019re wondering which functions support the additional year-end argument, the answer is all those for which this would be relevant \u2013 here\u2019s the list for reference:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<p>Functions<\/p>\n<\/td>\n<td>\n<p>What they do<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>STARTOFYEAR, ENDOFYEAR<\/p>\n<\/td>\n<td>\n<p>Return the first or last date in the year for the current filter context.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>PREVIOUSYEAR, NEXTYEAR<\/p>\n<\/td>\n<td>\n<p>Return a table of the dates in the previous or next year, based on the current filter context\u2019s latest date.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>DATESYTD, TOTALYTD<\/p>\n<\/td>\n<td>\n<p>As covered on the previous page!<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>OPENINGBALANCEYEAR, CLOSINGBALANCEYEAR<\/p>\n<\/td>\n<td>\n<p>Return the opening or closing balance on the first\/last day of the year for the current filter context.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Referencing Previous Periods<\/h2>\n<p>Suppose that you want to show for each day, month, quarter or year what your sales were in the same period twelve months ago? Again, there are two ways (at least) to do this:<\/p>\n<ul>\n<li>Using the <code>DATEADD<\/code> function<\/li>\n<li>Using the <code>SAMEPERIODLASTYEAR<\/code> function<\/li>\n<\/ul>\n<p>The <code>DATEADD<\/code> function is more useful, as it can also show sales 13 months ago, or four years ago or indeed any number of periods of any type ago, but I\u2019ll explain both functions in the interest of fairness. Start by showing for each month the sales in that month against the sales in the same month in the previous quarter, which should give this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"339\" height=\"422\" class=\"wp-image-86367\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-40.png\" \/><\/p>\n<p>Note that I\u2019ve reverted to using the typical calendar month and year in the matrix, and I\u2019m sorting the calendar months by the <em>MonthNumber<\/em> column again.<\/p>\n<p>So, for example, the measure should show previous quarter sales for February 2019 as 26.68, since these were what the sales were three months earlier for the same period. You can\u2019t use the <code>SAMEPERIODLASTYEAR<\/code> function to do this for obvious reasons (the clue\u2019s in the name), and for some strange reason there isn\u2019t an equivalent <code>SAMEPERIODLASTMONTH<\/code> or <code>SAMEPERIODLASTQUARTER<\/code> function, so instead, you\u2019ll use the versatile <code>DATEADD<\/code> function. This takes three arguments:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"386\" height=\"69\" class=\"wp-image-86368\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-41.png\" \/><\/p>\n<p>The arguments are:<\/p>\n<ol>\n<li>The calendar dates, as usual<\/li>\n<li>The number of intervals to go forward in time<\/li>\n<li>The interval to use<\/li>\n<\/ol>\n<p>Here\u2019s what you\u2019ll see for the third argument when typing it in:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"162\" height=\"134\" class=\"wp-image-86369\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-42.png\" \/><\/p>\n<p>For this example, you can either go three months back in time or one quarter; it makes no difference which you choose. I\u2019ve gone for three months, to produce this measure:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Previous quarter = CALCULATE(\r\n    SUM(Sales[Amount]),\r\n    \/\/ go back 3 months (could have used -1 QUARTER)\r\n    DATEADD('Calendar'[DateKey],-3,MONTH)\r\n)<\/pre>\n<p>Since the <code>DATEADD<\/code> function is so powerful (you can go forward or backwards in time, using days, months, quarters or years as the time interval), it seems pointless having the <code>SAMEPERIODLASTYEAR<\/code> function as a shortcut for it. Nevertheless, it exists! To illustrate it, switch to showing for each period what sales were 12 months (i.e. one year) previously. You could solve this using this measure:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Previous year 1 = CALCULATE(\r\n    SUM(Sales[Amount]),\r\n    SAMEPERIODLASTYEAR('Calendar'[DateKey])\r\n)<\/pre>\n<p>Or this measure:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Previous year 2 = CALCULATE(\r\n    SUM(Sales[Amount]),\r\n    DATEADD('Calendar'[DateKey],-1,YEAR)\r\n)<\/pre>\n<p>To prove this, here are both measures in the matrix, showing that they both return 9.49 against February 2019, since that\u2019s what sales were for the corresponding period 12 months previously:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"449\" height=\"475\" class=\"wp-image-86370\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-43.png\" \/><\/p>\n<h2>Getting the Whole of a Previous Period<\/h2>\n<p>The functions above return a figure for a corresponding period, but what happens if you want to get sales for the whole of the previous period? To see what this means, consider this example (it shows year-to-date figures as a fraction of total sales for the whole of the previous year):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"639\" class=\"wp-image-86371\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-44.png\" \/><\/p>\n<p>The figure shown for May 2019 (boxed above) is 33.40%, since year-to-date sales at this point are 39.19, and sales for the whole of the previous 12-month period were 117.35. 39.19 divided by 17.35 gives 33.40%. The fact that by the end of 2019, the sales have exceeded 100% of the sales for the whole of the previous year is presumably a good sign!<\/p>\n<p>To calculate this measure, use the <code>PARALLELPERIOD<\/code> function. This has the same format as the <code>DATEADD<\/code> function but returns the aggregate figure for the whole of a previous period, rather than for the period corresponding to the one you\u2019re viewing. The syntax of the function is as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"548\" height=\"96\" class=\"wp-image-86372\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-45.png\" \/><\/p>\n<p>The interval can be any one of the following:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"115\" height=\"73\" class=\"wp-image-86373\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-46.png\" \/><\/p>\n<p>Note that unlike for the <code>DATEADD<\/code> function you can\u2019t use the <code>PARALLELPERIOD<\/code> function to return the aggregate of a number for the whole of the previous day, presumably because this is at too low a level of granularity.<\/p>\n<p>Putting all this together, here\u2019s how the measure to give the figures above might read:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Cumulative % previous year = DIVIDE(\r\n    \/\/ divide the year-to-date figure \u2026\r\n    CALCULATE(\r\n        SUM(Sales[Amount]),\r\n        DATESYTD('Calendar'[DateKey])\r\n    ),\r\n    \/\/ \u2026 by sales for the whole of the previous year\r\n    CALCULATE(\r\n        SUM(Sales[Amount]),\r\n        PARALLELPERIOD('Calendar'[DateKey],-1,YEAR)\r\n    )\r\n)<\/pre>\n<p>That is: divide year-to-date sales by sales for the whole of the previous year.<\/p>\n<p>To format the measure, select it in the list of fields. Then, on the Modeling ribbon, format as a percentage with two decimal places.<\/p>\n<h2>Moving Averages<\/h2>\n<p>Moving averages are one of the most useful ways to show trends, since they iron out any seasonal effects. Sadly, there is no <code>MOVINGAVERAGE<\/code> function in DAX, but you can create your own expression in a couple of different ways, of which I\u2019ve shown the one I believe to be the more useful below.<\/p>\n<p>To illustrate moving averages, first create a relationship between the <em>Weight<\/em> and the <em>Calendar<\/em> tables:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"296\" height=\"196\" class=\"wp-image-86374\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-47.png\" \/><\/p>\n<p>The <em>Weight<\/em> table is a bit of an anomaly \u2013 it doesn\u2019t have anything to do with the others. I\u2019ve been recording my weight roughly every week for the last couple of years, to see if it\u2019s going up or down. Although this is slightly obsessive behaviour, it does provide a perfect example of the use of moving averages.<\/p>\n<p>Add a calculated column to the <em>Calendar<\/em> table:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"364\" class=\"wp-image-86375\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-48.png\" \/><\/p>\n<p>The new column should use this formula:<\/p>\n<pre class=\"lang:c# theme:vs2012 \">YearMonth = [YearNumber] &amp;\"-\"&amp; if([MonthNumber]&lt;10,\"0\",\"\") \r\n    &amp; [MonthNumber]<\/pre>\n<p>This column should return the year number and month number for each calendar date, which you can then use to display as labels on a chart:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"908\" height=\"239\" class=\"wp-image-86376\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-49.png\" \/><\/p>\n<p>Now create a line chart showing the average of the <em>Kilos<\/em> field from the <em>Weight<\/em> table against the <em>YearMonth<\/em> field from the <em>Calendar<\/em> table:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"226\" height=\"286\" class=\"wp-image-86377\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-50.png\" \/><\/p>\n<p>Make sure that you choose to show the average kilos, not the default sum. Also, you will need to sort your chart by the <em>YearMonth<\/em> field, not by the average kilos (the default):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"486\" height=\"294\" class=\"wp-image-86378\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-51.png\" \/><\/p>\n<p>You should get something like this (I\u2019ve formatted my chart a bit, but it\u2019s the underlying trend which interests us here):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"760\" height=\"343\" class=\"wp-image-86379\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-52.png\" \/><\/p>\n<p>The question is this \u2013 is my weight going up or down? To answer this, you have to take account of seasonality \u2013I eat way too much at Christmas but tend to go on family cycling holidays in July during which my weight falls. To show what\u2019s happening, create a 12-month moving average. If this works, the figure for February 2019, for example, should return the average for the previous 12 months (that is for the period March 2018 through to February 2019).<\/p>\n<p>Here\u2019s a measure you could create to show the 12-month moving average:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Moving average weight = CALCULATE(\r\n\u00a0\u00a0\u00a0\u00a0-- average weight in kilos ...\r\n\u00a0\u00a0\u00a0\u00a0AVERAGE('Weight'[Kilos]),\r\n\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0-- ... over the period between two dates, \r\n\u00a0\u00a0\u00a0\u00a0-- as specified in the arguments\r\n\u00a0\u00a0\u00a0\u00a0DATESBETWEEN(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Calendar'[DateKey],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- the first date takes the last date\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- for the filter context, works out\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- what the corresponding period would \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- have been for the previous year and \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- adds one day to the last date of it\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0NEXTDAY(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SAMEPERIODLASTYEAR(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0LASTDATE('Calendar'[DateKey])\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- the last date is just the end date\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- for the filter context\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0LASTDATE('Calendar'[DateKey])\r\n\u00a0\u00a0\u00a0\u00a0)\r\n) <\/pre>\n<p>Here\u2019s the chart this would give, and it looks like good news \u2013 my weight may be going up and down, but on a seasonally adjusted basis it\u2019s falling steadily, if slowly:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"449\" class=\"wp-image-86380\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-53.png\" \/><\/p>\n<p>To understand how the measure works, create a table to include these fields:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"219\" height=\"173\" class=\"wp-image-86381\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-54.png\" \/><\/p>\n<p>This table should show the following data (I\u2019ve added the red box separately \u2013 you obviously won\u2019t be able to create this in Power BI):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"438\" height=\"464\" class=\"wp-image-86382\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-55.png\" \/><\/p>\n<p>The 12-month moving average for February 2019 is 82.62 and is shown selected above. This is the average of the figures for the 12 months shown in the red box. To see how the measure arrives at this figure, start in the middle of it:<\/p>\n<pre class=\"lang:c# theme:vs2012\">LASTDATE('Calendar'[DateKey]<\/pre>\n<p>This expression would return 28<sup>th<\/sup> February 2019 for the above example (being the last date in the date filter context period for the month under consideration). Now add the next bit of the measure:<\/p>\n<pre class=\"lang:c# theme:vs2012\">SAMEPERIODLASTYEAR(\r\n    LASTDATE('Calendar'[DateKey])\r\n)<\/pre>\n<p>This expression will give 28h February 2018, being the corresponding date in the previous calendar year. Expand the measure a bit more and you get:<\/p>\n<pre class=\"lang:c# theme:vs2012\">NEXTDAY(\r\nSAMEPERIODLASTYEAR(\r\n     LASTDATE('Calendar'[DateKey])\r\n)\r\n)<\/pre>\n<p>This expression will give the day following 28<sup>th<\/sup> February 2018 (that is, 1<sup>st<\/sup> March 2018). So the whole date range across which you\u2019re averaging my weight is given by:<\/p>\n<pre class=\"lang:c# theme:vs2012\">DATESBETWEEN(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Calendar'[DateKey],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- the first date takes the last date\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- for the filter context, works out\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- what the corresponding period would \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- have been for the previous year and \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- adds one day to the last date of it\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0NEXTDAY(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0SAMEPERIODLASTYEAR(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0LASTDATE('Calendar'[DateKey])\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- the last date is just the end date\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-- for the filter context\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0LASTDATE('Calendar'[DateKey])\r\n\u00a0\u00a0\u00a0\u00a0)<\/pre>\n<p>This gives the dates between 1<sup>st<\/sup> March 2018 and 28<sup>th<\/sup> February 2019, which was the goal!<\/p>\n<h2>Semi-additive Measures<\/h2>\n<p>For the last part of this tutorial on using time-intelligence functions, I\u2019ll discuss semi-additive measures (that is, measures which sometimes aggregate data and sometimes don\u2019t). To start, create a new layout in your report, and create this relationship:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"485\" height=\"275\" class=\"wp-image-86383\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-56.png\" \/><\/p>\n<p>Suppose that the <em>Balance<\/em> table contains your bank statement for the period July to September 2019. You want to get the closing bank balance at the end of each month, so you create a report based on this <em>Balance<\/em> table:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"645\" height=\"263\" class=\"wp-image-86384\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-57.png\" \/><\/p>\n<p>To do this, you add a table with these fields:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"218\" height=\"148\" class=\"wp-image-86385\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-58.png\" \/><\/p>\n<p>You should now see this table (if you include a slicer as shown to look at 2019 data only):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"234\" height=\"276\" class=\"wp-image-86386\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-59.png\" \/><\/p>\n<p>This result is clearly wrong (it would be nice if your bank added your daily balances to get your monthly balance, assuming that you aren\u2019t overdrawn, but life doesn\u2019t work that way). The goal is to pick out the last amount in each month. Fortunately, there is a family of semi-additive DAX functions to draw on:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<p>Function(s)<\/p>\n<\/td>\n<td>\n<p>What the functions do<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>CLOSINGBALANCEYEAR, CLOSINGBALANCEQUARTER, CLOSINGBALANCEMONTH, OPENINGBALANCEYEAR, OPENINGBALANCEQUARTER, OPENINGBALANCEMONTH<\/p>\n<\/td>\n<td>\n<p>Calculate the value of an expression at the first or last date of the year, quarter or month for the current filter context.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>FIRSTDATE, LASTDATE<\/p>\n<\/td>\n<td>\n<p>Return the first or last date for the filter context.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>FIRSTNONBLANK, LASTNONBLANK<\/p>\n<\/td>\n<td>\n<p>Return the first or last date for the filter context for which a given expression has a value.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>For this example, you could try using the <code>LASTDATE<\/code> function, with this measure:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Attempt at closing balance = CALCULATE(\r\n\u00a0\u00a0\u00a0\u00a0-- work out the total balance ...\r\n\u00a0\u00a0\u00a0\u00a0SUM(Balance[Balance]),\r\n\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0-- for the last date in the current\r\n\u00a0\u00a0\u00a0\u00a0-- filter context\r\n\u00a0\u00a0\u00a0\u00a0LASTDATE('Calendar'[DateKey])\r\n\u00a0\u00a0\u00a0\u00a0\r\n)<\/pre>\n<p>This formula would give this column in the table:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"488\" height=\"273\" class=\"wp-image-86387\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-60.png\" \/><\/p>\n<p>This formula is a bit better, but it only shows figures for July. This is because in the table of balances, there weren\u2019t any transactions on the last dates of August or September in 2019, so the measure is returning blank for these two months. You could get around this by using the clever <code>LASTNONBLANK<\/code> function, which will return the balance on the last date for which a transaction exists:<\/p>\n<pre class=\"lang:c# theme:vs2012\">Closing balance = CALCULATE(\r\n\u00a0\u00a0\u00a0\u00a0\/\/ work out the total balance ...\r\n\u00a0\u00a0\u00a0\u00a0SUM(Balance[Balance]),\r\n\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0LASTNONBLANK(\r\n\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ ... for the last date in the current filter context ...\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0'Calendar'[DateKey],\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ ... for which there are rows in the table of balances\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0COUNTROWS(RELATEDTABLE(Balance))\r\n\u00a0\u00a0\u00a0\u00a0)\u00a0\u00a0\u00a0\r\n)<\/pre>\n<p>This measure will give the correct closing balances. The function is called semi-additive because you could then aggregate these if you chose, although normally you won\u2019t want to do this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"362\" height=\"274\" class=\"wp-image-86388\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-61.png\" \/><\/p>\n<p>The measure needs a bit of explanation. The syntax of the <code>LASTNONBLANK<\/code> function is as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"97\" class=\"wp-image-86389\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/02\/word-image-62.png\" \/><\/p>\n<p>The measure returns the total balance for each month on the last day for which there are any corresponding rows in the <em>Balance<\/em> table. The reason for the <code>RELATEDTABLE<\/code> function is that at this point in the measure it\u2019s slipped from filter to row context. The <code>LASTNONBLANK<\/code> function is an iterator function which goes down the rows in the current filter context (for this example, the dates in each month), evaluating for each whether it could be included. Relationships between tables aren\u2019t automatically supported within row context, so you need to use the <code>RELATEDTABLE<\/code> to bring information in from another table.<\/p>\n<p>It seems appropriate to end with this paragraph about row and filter context, since understanding these two concepts is key to understanding DAX. Thank you for reading through this article, and (perhaps) the other ones in this series, and happy DAXingthe date of the sale If you\u2019ve enjoyed the series, you may like to know that the author\u2019s company Wise Owl Training provide <a href=\"https:\/\/www.wiseowl.co.uk\/power-bi\/\">classroom training<\/a> in Power BI and DAX, although currently only in the UK.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, you\u2019ve learnt that you can override the default filter context for any measure referencing a calendar date column. The replacement filter context could, for example, allow you to return year-to-date figures, show data from the same period in a previous month, quarter or year, or even show totals from prior periods or moving averages. You\u2019ve also learnt how to use semi-additive measures to show closing (and by analogy) opening balances. You should also now have a feel for the fact that time-intelligence functions have this name because DAX has built-in knowledge of how days, months, quarters and years behave.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DAX contains a host of time-intelligence functions with exotic names such as SAMEPERIODLASTYEAR and PARALLELPERIOD. In the last article in this series, Andy Brown explains how to write measures using the range of date functions in DAX, and also explains how time-intelligence functions work behind the scenes. &hellip;<\/p>\n","protected":false},"author":9783,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143528],"tags":[6016],"coauthors":[6782],"class_list":["post-86343","post","type-post","status-publish","format-standard","hentry","category-bi-sql-server","tag-automated-delivery"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/86343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/9783"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=86343"}],"version-history":[{"count":4,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/86343\/revisions"}],"predecessor-version":[{"id":86391,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/86343\/revisions\/86391"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=86343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=86343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=86343"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=86343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}