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

Current Month and Previous Month for Selected Month in Slicer

All, I am new to Power BI

 

I have couple of measures for Current Month and Previous Month as below formula

I would like to tweak this formula or any other easy way to show Current Month Sales for the Selected Month in Slicer and the Previous Month to show the previous month or the month selected in Slicer

 

Current Month Sales = var current_month= MONTH(TODAY()) var current_year=YEAR(TODAY()) return 

CALCULATE(SUM(Table1.Sales),
FILTER(DATES_Dimension,MONTH(DATES_Dimension[CalndrDATE])=current_month), FILTER(DATES_Dimension,YEAR(DATES_Dimension[CalndrDATE])=current_year))
 
Previous Month Sales = var current_month= MONTH(TODAY()) var current_year=YEAR(TODAY()) return
CALCULATE(SUM(Table1.Sales),
FILTER(DATES_Dimension,MONTH(DATES_Dimension[CalndrDATE])=current_month-1), FILTER(DATES_Dimension,YEAR(DATES_Dimension[CalndrDATE])=current_year))
 
Thanks for your help
4 REPLIES 4
Anonymous
Not applicable

Use this DAX:

Last month Sales= CALCULATE([Total Sales],PREVIOUSMONTH(Date_Table[Date]))
This month Sales = Sum(Fact_Table[Sales])
 
And add slicer for month. "This month sales" will be the sales for the month you selected in slicer & "Last month Sales" will give sales prior to the month selected in slicer.
Greg_Deckler
Super User
Super User

People often solve this issue by creating a calculated column like this:

 

Months Past = 
VAR __today = CONCATENATE(YEAR(TODAY()),FORMAT(MONTH(TODAY()),"0#")) * 1
VAR __date = CONCATENATE(YEAR([Date]),FORMAT(MONTH([Date]),"0#")) * 1
RETURN
__today - __date

This will give you the number of months in the past, 0 is the current month, 1 is the previous month, etc.

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg

 

Thanks for this. I am not looking for another dimension in this case. 

If I implement the custom column, I get only 1 row of value when I choose a Month from slicer 

 

What I really need is, If I choose Feb from my Month Slice, I want to see Current Month Sales as Feb 2019 and Previous Month Sales as Jan 2019 

 

If I choose March in my slicer, want to see Current Month Sales as March 2019 and Previous Month sales as Feb 2019

 

Thanks

Jogesh

You generally disconnect your slicer and use the calculated column in a measure for selection purposes, so think of starting your measures out like:

 

This Month = 
VAR __table = FILTER('Table',[Months Ago] = 0)
RETURN
SUMX(__table,[Value])

Last Month
VAR __table = FILTER('Table',[Months Ago] = 1)
RETURN
SUMX(__table,[Value])

It's really difficult to answer precisely without example data and expected output, Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.