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
jlam
Frequent Visitor

Current Month Number DAX Formula for Current and Previous Year Sales

Hello everyone,

 

For my Power BI Desktop file, I am using Connx tables through a odbc connction. Sales for every year are stored in separate tables. For example, the 2018 table is labelled as DTYYMM2018, 2017 is labelled as DTYYMM2017. I have a Date table with a relationship to my Sales tables. 

 

The users have requested to have the current month sales in one visual and they would like to see the same month in the previous year in one visual (ex. June 2018 sales with June 2017 sales). Please see the following screenshot for the visualization.

 

1.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I have placed a visual level filter with the month number but the issue is that every month, I need to select the next month number manually and there are over 40 reports. I have found a DAX formula which can identify current month. 

 

 

CurrentMonth 2018 =
IF (YEAR (DTLMMY2018[InvoiceDate]) = YEAR ( TODAY () )
&& MONTH ( DTLMMY2018[InvoiceDate]) = MONTH ( TODAY () ),
"Yes",
"No") 

 

This formula works well for the current year but does not allow me to show the previous year and same month in a single visualization. Please see the following screenshot with the formula applied. It will show that current month sales and teh whole year sales from the previous year.

 

2.png

 

 

 

 

 

 

 

 

 

 

 

 

 

               

 

 

 

Can anyone advise a DAX formula which can provide the current month number that can be applied for any year as opposed to only the current year?

 

Thank you,

Jessica

1 REPLY 1
v-jiascu-msft
Employee
Employee

Hi Jessica,

 

What are the formulas you used? I would suggest you use a slicer in "Relative" mode and use the "SAMEPERIODLASTYEAR" in the formula. 

Current_Month_Number_DAX_Formula_for_Current_and_Previous_Year_Sales

 

Best Regards,

Dale

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

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.