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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
VamshiGoud
Frequent Visitor

How to show Current Month and Previous Month values if user selects Month name

Hello ,

 

I havea  requirement where i want to show Current month and Previous month Sales Amount in table visual. However when user filters the year and month name slicer those CM, PM values should change accordingly.

 

Ex : If Month slicer Mar selected CM value should show N Month (Mar) amount and PM should show N-1 Month (Feb amount). Same way if Feb selected CM should show Feb and PM should show Jan. It means PM measure should always show N-1 Month values as per the selected Month from Month slicers 

Note : It should work as per the financial year. Financial year starts from Apr-Mar

Sample Data

DateYearMonthProductValues
01 October 20242024OctA20
01 November 20242024NovB10
01 December 20242024DecC30
01 January 20252025JanA20
01 February 20252025FebB10
01 March 20252025MarC30

Appricate your help. Thanks in Advance

1 ACCEPTED SOLUTION
grazitti_sapna
Super User
Super User

Hi @VamshiGoud , 

You can achieve this by creating two DAX measures:

  1. Current Month Sales (CM)

  2. Previous Month Sales (PM)

CM Sales = 
VAR SelectedMonth = SELECTEDVALUE('Table'[Month])
VAR SelectedYear = SELECTEDVALUE('Table'[Year])
RETURN
CALCULATE(
SUM('Table'[Values]),
'Table'[Month] = SelectedMonth,
'Table'[Year] = SelectedYear
)

Another one:- 

PM Sales = 
VAR SelectedMonth = SELECTEDVALUE('Table'[Month])
VAR SelectedYear = SELECTEDVALUE('Table'[Year])

-- Create a mapping for financial months to numeric order
VAR MonthOrder =
SWITCH(SelectedMonth,
"Apr", 1, "May", 2, "Jun", 3, "Jul", 4, "Aug", 5, "Sep", 6,
"Oct", 7, "Nov", 8, "Dec", 9, "Jan", 10, "Feb", 11, "Mar", 12
)

-- Find the Previous Month and adjust the Year if needed
VAR PrevMonthOrder = IF(MonthOrder = 1, 12, MonthOrder - 1)
VAR PrevYear = IF(MonthOrder = 1, SelectedYear - 1, SelectedYear)

-- Find Previous Month Name
VAR PrevMonthName =
SWITCH(PrevMonthOrder,
1, "Apr", 2, "May", 3, "Jun", 4, "Jul", 5, "Aug", 6, "Sep",
7, "Oct", 8, "Nov", 9, "Dec", 10, "Jan", 11, "Feb", 12, "Mar"
)

RETURN
CALCULATE(
SUM('Table'[Values]),
'Table'[Month] = PrevMonthName,
'Table'[Year] = PrevYear
)

🌟 I hope this solution helps you unlock your Power BI potential!

If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.

💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.

🎖 As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.

🔗 Curious to explore more? [Discover here].

Let’s keep building smarter solutions together!

 

View solution in original post

3 REPLIES 3
VamshiGoud
Frequent Visitor

It's working as i expected . Thanks a Lot 🙂

danextian
Super User
Super User

Hi @VamshiGoud 

 

Time intelligence calculations should be relatively simple with a separate dates dimension table that's been marked as a dates table. The dates table is connected to your fact table in a single direction one-to-many relationship.

danextian_0-1743145836799.png

danextian_1-1743146387951.png

danextian_2-1743146404475.png

 

 

You can use PREVIOUSMONTH to get the prior month's value relative the current row month or whatever is selected in the slicer.

Total Revenue Previous Month =
CALCULATE (
    [Total Revenue],
    PREVIOUSMONTH ( Dates[Date] ),
    REMOVEFILTERS ( Dates )
)

REMOVEFILTERS is not necessary if the dates table has been marked as such.  -https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-date-tables

 

Please see the attached sample pbix.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
grazitti_sapna
Super User
Super User

Hi @VamshiGoud , 

You can achieve this by creating two DAX measures:

  1. Current Month Sales (CM)

  2. Previous Month Sales (PM)

CM Sales = 
VAR SelectedMonth = SELECTEDVALUE('Table'[Month])
VAR SelectedYear = SELECTEDVALUE('Table'[Year])
RETURN
CALCULATE(
SUM('Table'[Values]),
'Table'[Month] = SelectedMonth,
'Table'[Year] = SelectedYear
)

Another one:- 

PM Sales = 
VAR SelectedMonth = SELECTEDVALUE('Table'[Month])
VAR SelectedYear = SELECTEDVALUE('Table'[Year])

-- Create a mapping for financial months to numeric order
VAR MonthOrder =
SWITCH(SelectedMonth,
"Apr", 1, "May", 2, "Jun", 3, "Jul", 4, "Aug", 5, "Sep", 6,
"Oct", 7, "Nov", 8, "Dec", 9, "Jan", 10, "Feb", 11, "Mar", 12
)

-- Find the Previous Month and adjust the Year if needed
VAR PrevMonthOrder = IF(MonthOrder = 1, 12, MonthOrder - 1)
VAR PrevYear = IF(MonthOrder = 1, SelectedYear - 1, SelectedYear)

-- Find Previous Month Name
VAR PrevMonthName =
SWITCH(PrevMonthOrder,
1, "Apr", 2, "May", 3, "Jun", 4, "Jul", 5, "Aug", 6, "Sep",
7, "Oct", 8, "Nov", 9, "Dec", 10, "Jan", 11, "Feb", 12, "Mar"
)

RETURN
CALCULATE(
SUM('Table'[Values]),
'Table'[Month] = PrevMonthName,
'Table'[Year] = PrevYear
)

🌟 I hope this solution helps you unlock your Power BI potential!

If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.

💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.

🎖 As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.

🔗 Curious to explore more? [Discover here].

Let’s keep building smarter solutions together!

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.