{"id":4763,"date":"2023-03-10T18:31:40","date_gmt":"2023-03-10T18:31:40","guid":{"rendered":"https:\/\/monocroft.com\/?p=4763"},"modified":"2023-03-10T18:31:42","modified_gmt":"2023-03-10T18:31:42","slug":"how-to-calculate-rolling-x-months-in-power-bi","status":"publish","type":"post","link":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/","title":{"rendered":"How to Calculate Rolling X Months in Power BI"},"content":{"rendered":"\n

Rolling X is a useful feature that enables you to calculate the cumulative total or average of a specific metric over a defined period of time. It is commonly used in financial analysis, sales forecasting, and other data-driven processes.<\/p>\n\n\n\n

For example, if X=3, rolling 3 months of sales will be the sum or average of the sales for the past three months, and this period will update each month to include the most recent three months.<\/p>\n\n\n\n

In this article, I will walk you through different ways to calculate rolling X months in Power BI, using DAX formulas.<\/p>\n\n\n\n

Read to learn more.<\/p>\n\n\n\n

Introduction<\/h2>\n\n\n\n

To calculate rolling X months in Power BI, you need a date column that contains the dates that you want to calculate. Once you have your dates table set up, you can do some great data-based analysis.<\/p>\n\n\n\n

Also, you must create a measure for the value you want to calculate using any aggregation function such as SUM, AVERAGE, MIN, MAX<\/strong><\/code>, etc. You will use this measure to calculate the rolling X months value.<\/p>\n\n\n\n

In Power BI, you can calculate rolling X months in different ways, using different functions such as the DATESINPERIOD, EARLIER, RANKX, DATESBETWEEN<\/strong><\/code> functions, etc. I will explain each of them.<\/p>\n\n\n\n

1. Using the DATESINPERIOD function<\/h2>\n\n\n\n

You can use the DATESINPERIOD <\/strong><\/code>function to calculate rolling X months by following the steps below:<\/p>\n\n\n\n

The first thing to do is to create a measure for the value you want to calculate. This measure will be used to calculate the rolling X months value. For example, if you want to calculate the rolling X months average, you will use the AVERAGE<\/code> <\/strong>function.<\/p>\n\n\n\n

Average_Sales = AVERAGE(SalesTable[SalesAmount])<\/strong><\/code><\/pre>\n\n\n\n

After that, create a measure for the rolling X months. To do that, use the following DAX formula for the measure you created for the rolling X months.<\/p>\n\n\n\n

Rolling X Months = \nCALCULATE (\n    [Average_Sales],\n    DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), X, MONTH )\n)<\/code><\/strong><\/pre>\n\n\n\n

Replace [Average_Sales]<\/strong><\/code> with the name of the measure you created in the first step (I used the one I created in this example). Replace X <\/strong>with the number of months you want to include in the rolling calculation.<\/p>\n\n\n\n

2. Using the EARLIER function<\/h2>\n\n\n\n

You can also use the EARLIER <\/strong><\/code>function to create a rolling X months calculation. To do that, follow the below steps:<\/p>\n\n\n\n

Create a measure for the value you want to calculate (just like I did earlier). Then create a measure for the rolling X months using the following DAX formula. Use the following DAX formula:<\/p>\n\n\n\n

Rolling X Months =\nVAR CurrentDate = MAX ( 'Date'[Date] )\nRETURN\n    CALCULATE (\n        [Your Measure],\n        FILTER (\n            ALL ( 'Date' ),\n            'Date'[Date] >= DATEADD ( CurrentDate, -X, MONTH )\n                && 'Date'[Date] <= CurrentDate\n        )\n    )<\/code><\/strong><\/pre>\n\n\n\n

Replace [Your Measure]<\/code> with the name of the measure you created in step 1, and replace X <\/strong>with the number of months you want to include in the rolling calculation.<\/p>\n\n\n\n

The first line defines a variable called CurrentDate<\/strong>. You can replace it in this formula with any date column or variable that contains the current date you want to use as a reference point for the rolling X months period.<\/p>\n\n\n\n

NB: The <\/em>EARLIER <\/strong><\/code>function is not used in the above formula, but can be used in a similar context to reference a previous value.<\/em><\/p>\n\n\n\n

3. Using the DATESBETWEEN function<\/h2>\n\n\n\n

To use the DATESBETWEEN <\/strong><\/code>function, create a measure for the value you want to calculate, and create a measure for the rolling X months using the following DAX formula:<\/p>\n\n\n\n

Rolling X Months = \nCALCULATE (\n    [Your Measure],\n    DATESBETWEEN (\n        'Date'[Date],\n        DATEADD ( LASTDATE ( 'Date'[Date] ), -X, MONTH ),\n        LASTDATE ( 'Date'[Date] )\n    )\n)<\/code><\/strong><\/pre>\n\n\n\n

Replace [Your Measure]<\/strong><\/code> with the name of the measure you created in step 2, and replace X<\/strong><\/code> with the number of months you want to include in the rolling X.<\/p>\n\n\n\n

4. Using the RANKX function<\/h2>\n\n\n\n

Finally, you can use the RANKX <\/strong><\/code>function to create a rolling X months calculation through the following steps:<\/p>\n\n\n\n

Create a measure for the value you want to calculate, and then create a measure for the rolling X months using the following DAX formula:<\/p>\n\n\n\n

Rolling X Months =\nVAR SelectedDate = MAX ( 'Date'[Date] )\nVAR DatesRanked = RANKX ( ALL ( 'Date' ), 'Date'[Date],, ASC )\nVAR RollingDates =\n    FILTER (\n        ALLSELECTED ( 'Date' ),\n        DatesRanked >= DatesRanked - X\n            && DatesRanked <= DatesRanked\n    )\nRETURN\n    CALCULATE (\n        [Your Measure],\n        'Date'[Date] IN RollingDates, \n        ALLSELECTED ( 'Date' )\n    )<\/code><\/strong><\/pre>\n\n\n\n

Replace [Your Measure]<\/code> <\/strong>with the name of the measure you created in step 1, and replace X<\/code> with the number of months, you want to include in the rolling calculation.<\/p>\n\n\n\n

Conclusion<\/h2>\n\n\n\n

Calculating rolling X months in Power BI is a powerful technique that allows you to explore data trends and patterns over a specified period of time, and there are multiple ways to calculate it depending on the data and the specific requirements.<\/p>\n\n\n\n

The DATESINPERIOD, EARLIER, <\/strong><\/code>and RANKX<\/strong><\/code> functions can all be used to calculate rolling X months, and each formula has its advantages and limitations.<\/p>\n\n\n\n

By using one of these formulas, you can create a rolling X months calculation that fits your needs and helps you gain insights from your data.<\/p>\n\n\n\n

I hope you understood these steps.<\/p>\n\n\n\n

Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"

Rolling X is a useful feature that enables you to calculate the cumulative total or average of a specific metric … <\/p>\n

Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":4765,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,8],"tags":[],"yoast_head":"\nHow to Calculate Rolling X Months in Power BI - Monocroft<\/title>\n<meta name=\"description\" content=\"In this article, i will walk you through how to calculate rolling X months in Power BI using DAX formulas to make data-driven decisions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Calculate Rolling X Months in Power BI - Monocroft\" \/>\n<meta property=\"og:description\" content=\"In this article, i will walk you through how to calculate rolling X months in Power BI using DAX formulas to make data-driven decisions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/\" \/>\n<meta property=\"og:site_name\" content=\"Monocroft\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-10T18:31:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-10T18:31:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"720\" \/>\n\t<meta property=\"og:image:height\" content=\"405\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Matt\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matt\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/\"},\"author\":{\"name\":\"Matt\",\"@id\":\"https:\/\/monocroft.com\/#\/schema\/person\/3aeab97c9b5661d211c0742c48f024b3\"},\"headline\":\"How to Calculate Rolling X Months in Power BI\",\"datePublished\":\"2023-03-10T18:31:40+00:00\",\"dateModified\":\"2023-03-10T18:31:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/\"},\"wordCount\":711,\"publisher\":{\"@id\":\"https:\/\/monocroft.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg\",\"articleSection\":[\"Guides\",\"PowerBI\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/\",\"url\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/\",\"name\":\"How to Calculate Rolling X Months in Power BI - Monocroft\",\"isPartOf\":{\"@id\":\"https:\/\/monocroft.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg\",\"datePublished\":\"2023-03-10T18:31:40+00:00\",\"dateModified\":\"2023-03-10T18:31:42+00:00\",\"description\":\"In this article, i will walk you through how to calculate rolling X months in Power BI using DAX formulas to make data-driven decisions.\",\"breadcrumb\":{\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#primaryimage\",\"url\":\"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg\",\"contentUrl\":\"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg\",\"width\":720,\"height\":405,\"caption\":\"how to calculate rolling X months - monocroft\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/monocroft.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Calculate Rolling X Months in Power BI\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/monocroft.com\/#website\",\"url\":\"https:\/\/monocroft.com\/\",\"name\":\"Monocroft\",\"description\":\"Monocroft Tech\",\"publisher\":{\"@id\":\"https:\/\/monocroft.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/monocroft.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/monocroft.com\/#organization\",\"name\":\"Triburge\",\"url\":\"https:\/\/monocroft.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/monocroft.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/07\/monocroft-logo.png\",\"contentUrl\":\"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/07\/monocroft-logo.png\",\"width\":512,\"height\":512,\"caption\":\"Triburge\"},\"image\":{\"@id\":\"https:\/\/monocroft.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/monocroft.com\/#\/schema\/person\/3aeab97c9b5661d211c0742c48f024b3\",\"name\":\"Matt\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/monocroft.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c06bcee4d38a649222493c5e9f11f7a5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c06bcee4d38a649222493c5e9f11f7a5?s=96&d=mm&r=g\",\"caption\":\"Matt\"},\"url\":\"https:\/\/monocroft.com\/author\/matthew\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Calculate Rolling X Months in Power BI - Monocroft","description":"In this article, i will walk you through how to calculate rolling X months in Power BI using DAX formulas to make data-driven decisions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/","og_locale":"en_US","og_type":"article","og_title":"How to Calculate Rolling X Months in Power BI - Monocroft","og_description":"In this article, i will walk you through how to calculate rolling X months in Power BI using DAX formulas to make data-driven decisions.","og_url":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/","og_site_name":"Monocroft","article_published_time":"2023-03-10T18:31:40+00:00","article_modified_time":"2023-03-10T18:31:42+00:00","og_image":[{"width":720,"height":405,"url":"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg","type":"image\/jpeg"}],"author":"Matt","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Matt","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#article","isPartOf":{"@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/"},"author":{"name":"Matt","@id":"https:\/\/monocroft.com\/#\/schema\/person\/3aeab97c9b5661d211c0742c48f024b3"},"headline":"How to Calculate Rolling X Months in Power BI","datePublished":"2023-03-10T18:31:40+00:00","dateModified":"2023-03-10T18:31:42+00:00","mainEntityOfPage":{"@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/"},"wordCount":711,"publisher":{"@id":"https:\/\/monocroft.com\/#organization"},"image":{"@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#primaryimage"},"thumbnailUrl":"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg","articleSection":["Guides","PowerBI"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/","url":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/","name":"How to Calculate Rolling X Months in Power BI - Monocroft","isPartOf":{"@id":"https:\/\/monocroft.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#primaryimage"},"image":{"@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#primaryimage"},"thumbnailUrl":"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg","datePublished":"2023-03-10T18:31:40+00:00","dateModified":"2023-03-10T18:31:42+00:00","description":"In this article, i will walk you through how to calculate rolling X months in Power BI using DAX formulas to make data-driven decisions.","breadcrumb":{"@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#primaryimage","url":"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg","contentUrl":"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/03\/how-to-calculate-rolling-X-months-monocroft.jpg","width":720,"height":405,"caption":"how to calculate rolling X months - monocroft"},{"@type":"BreadcrumbList","@id":"https:\/\/monocroft.com\/how-to-calculate-rolling-x-months-in-power-bi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/monocroft.com\/"},{"@type":"ListItem","position":2,"name":"How to Calculate Rolling X Months in Power BI"}]},{"@type":"WebSite","@id":"https:\/\/monocroft.com\/#website","url":"https:\/\/monocroft.com\/","name":"Monocroft","description":"Monocroft Tech","publisher":{"@id":"https:\/\/monocroft.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/monocroft.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/monocroft.com\/#organization","name":"Triburge","url":"https:\/\/monocroft.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/monocroft.com\/#\/schema\/logo\/image\/","url":"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/07\/monocroft-logo.png","contentUrl":"https:\/\/monocroft.com\/wp-content\/uploads\/2023\/07\/monocroft-logo.png","width":512,"height":512,"caption":"Triburge"},"image":{"@id":"https:\/\/monocroft.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/monocroft.com\/#\/schema\/person\/3aeab97c9b5661d211c0742c48f024b3","name":"Matt","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/monocroft.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c06bcee4d38a649222493c5e9f11f7a5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c06bcee4d38a649222493c5e9f11f7a5?s=96&d=mm&r=g","caption":"Matt"},"url":"https:\/\/monocroft.com\/author\/matthew\/"}]}},"_links":{"self":[{"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/posts\/4763"}],"collection":[{"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/comments?post=4763"}],"version-history":[{"count":149,"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/posts\/4763\/revisions"}],"predecessor-version":[{"id":5022,"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/posts\/4763\/revisions\/5022"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/media\/4765"}],"wp:attachment":[{"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/media?parent=4763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/categories?post=4763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monocroft.com\/wp-json\/wp\/v2\/tags?post=4763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}