Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
maatiash
Frequent Visitor

Dax formula for creating rolling months with condition

Hi Everyone 😊

 

I'm trying to create a Rolling Month field in DAX with a condition. Note: the examples below are the screenshots from Excel to show what output I want to get in Power BI. Hope it is clear 🙂

 

The conditon is described below:

When the field Aligned is filtered to No, then the Rolling Month is calculated for each country for the most current available month. It is shown below:

 

maatiash_0-1674045763619.png

When field is filtered to "Yes" then it is aligning all fields to the month where Sales are available and calculating month accordingly. You may see below an example:

 

maatiash_1-1674045800469.png

I also attached the PBIX file, where you can check details:

maatiash_2-1674046551291.png

Any help much appreciated, thank you!

 

Link to the PBIX file is here:

https://drive.google.com/drive/folders/1CGU2XIhiC2K2kWd9984tTxbWmX3G42uA?usp=share_link

 

Regards,
Matias

 

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @maatiash 

You can create a mesure:

Rolling month = "M"&COUNTROWS(FILTER(ALLSELECTED(CountryData),[Country]=MAX([Country])&&MONTH(CountryData[Reporting Date])>=MONTH(MAX([Reporting Date]))))

and set the following filter in visual filter:

vxinruzhumsft_0-1674109484199.png

Output:

vxinruzhumsft_1-1674109509252.png

.

vxinruzhumsft_2-1674109516373.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xinruzhu-msft
Community Support
Community Support

Hi @maatiash 

You can create a mesure:

Rolling month = "M"&COUNTROWS(FILTER(ALLSELECTED(CountryData),[Country]=MAX([Country])&&MONTH(CountryData[Reporting Date])>=MONTH(MAX([Reporting Date]))))

and set the following filter in visual filter:

vxinruzhumsft_0-1674109484199.png

Output:

vxinruzhumsft_1-1674109509252.png

.

vxinruzhumsft_2-1674109516373.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Yolo, 

 

Thank you for your help! Please let me to test, so I'll let you know if it works 🙂

 

Thanks and Regards,

Matias

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors