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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
PowerBigginer
Helper II
Helper II

Sameperiodlastyear till to date based on selection in year and month selection

Hello Everyone,

I'm new to this forum and need help with a DAX calculation. When I select a year in the slicer, I want to see the sales amount for the corresponding year of the previous year. If I select both a year and a month, I'm looking for the sales amount for the same month of the previous year. Additionally, if I choose the current month in the slicer, I want to see the total sales amount from the previous year up to the selected date which means till 23rd of Jan 2023.

If I select 2023 in year and Jan in month slicer I want to see the sales amount for the entire month of January 2022.

I've created a DAX formula that works correctly for the current month. However, when I select January 2023, the result only includes data until January 22, 2022. My goal is to retrieve the entire sales data for January 2022 when selecting January 2023 in the year and month slicers.

Here is my Dax

CALCULATE(
SUM('tbl_Sales Header'[FINANCE_AMOUNT]),
SAMEPERIODLASTYEAR(
DATESYTD('Calendar Table'[Date])
),
FILTER(
ALL('Calendar Table'),
'Calendar Table'[MonthNum] <= (MONTH(NOW())-1)
)
)+
CALCULATE(
SUM('tbl_Sales Header'[FINANCE_AMOUNT]),
SAMEPERIODLASTYEAR(
DATESYTD('Calendar Table'[Date])
),
FILTER(
ALL('Calendar Table'),
'Calendar Table'[MonthNum] = MONTH(NOW())
&& DAY('Calendar Table'[Date]) <= DAY(NOW())
)
)

I appreciate any guidance or corrections to my DAX formula.


2 REPLIES 2
PowerBigginer
Helper II
Helper II

@Fowmy  Thanks For your responce this is working fine for last years(if I select 2023 Jan I am getting correct result for 2022 Jan) but when I select current Month value is showing wrong and when I select feb 2024 I am getting huge amount My requirement is when I select current month the previous year value should get till the date. If I select Feb also I should get the value last year of till the date(Till Jan 23). 

Fowmy
Super User
Super User

@PowerBigginer 

Follow this patter, it caluclates the sales up to the date where there is sales for current and previous periods, it could be month, year, week and so on:

MoM = 

VAR __CM = [Sales Amount]
VAR __Period = DATEADD( DATESBETWEEN( 'Date'[Date] , MIN( 'Date'[Date] ) , MAX( 'Sales'[Order Date] ) ) , -1 , YEAR )
VAR __LYSM = CALCULATE( [Sales Amount] ,__Period )
RETURN
    __LYSM
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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