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
Anonymous
Not applicable

calculate the total sales of last 3 months vs current month of same year

hi i am new to power bi and i want to calculate the sales of last 3 months and compare with the current month. i have connected thye power bi with SSAS in a live mode . please help me 

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can refer to this sample of DAX:

current_month_sales = CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=MONTH(TODAY())))
last_3month_sales = 
var current_month= MONTH(TODAY()) 
var P_month = CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=current_month -1))
var p_p_month = CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=current_month -2))
return P_month + p_p_month + [current_month_sales]

 

Also You can refer to this post about using MDX to solve the problem

 

Best Regards,

Liang 

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

4 REPLIES 4
Anonymous
Not applicable

Hi, 

   I want to create a dashboard comparing the current month, previous month and previous 3 months. Since i have connected my powe bi with SSAS cube in LIve mode i cannot use the dateadd function as i am having duplicate dates in my data and i shows an error. please help me with it and provide me query or solution to fix my problem 

Anonymous
Not applicable

https://community.powerbi.com/t5/Desktop/Current-Month-Previous-Month-and-Before-Previous-Month/m-p/...

 

If you want to compare only the current month with the previous one then take the DAX-formular: "Previousmonth"

 

Kind regards, 

Frank

V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can refer to this sample of DAX:

current_month_sales = CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=MONTH(TODAY())))
last_3month_sales = 
var current_month= MONTH(TODAY()) 
var P_month = CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=current_month -1))
var p_p_month = CALCULATE(SUM('Table1'[Sales]),FILTER('Table1',MONTH('Table1'[Month])=current_month -2))
return P_month + p_p_month + [current_month_sales]

 

Also You can refer to this post about using MDX to solve the problem

 

Best Regards,

Liang 

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

Anonymous
Not applicable

Thank you

 

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.