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
Gem42
New Member

DAX Expression for Time Periods

Hi,

 

I am really struggling and hoping someone maybe able to help please.

 

I have a table of data with information ranging from 2022 – 2024.

 

In the PowerBI Dashboard, I want to show a Table visual which shows the total sales for 2024 vs the total sales for 2023.  I have also put a slicer on the page which allows the month that is displayed in the table visual to be selected. 

 

As a measure I have used the SAMPERIODLASTYEAR function to obtain the 2023 data, and if January is selected from the slicer, January 2023 is just shown, similarly if I select February only February 2023 is displayed and if I select both January and February I see February 2023 YTD data.

 

However for the 2024 data I can not figure out what the correct expression is that will give me January 2024 only, February 2024 only or January 2024 and February 2024 combined depending on which months are selected from the slicer?

 

Does anyone know what I should be using please?

 

Thank you

1 REPLY 1
lbendlin
Super User
Super User

I want to show a Table visual which shows the total sales for 2024 vs the total sales for 2023

That would be unfair to 2024, no?

 

SAMEPERIODLASTYEAR is part of the solution, but it is not sufficient.  You need to add a cutoff filter when you show YTD.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.