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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Skorcamp
Advocate I
Advocate I

How can I apply a previous year line on a Line & Stacked Column Chart that's being filtered

Profit PY = CALCULATE( FS[Profit],SAMEPERIODLASTYEAR(DimTime[Date].[Date]),FILTER(ALL(DimTime[Date].[Date]),DimTime[Date].[Date] >= [Start of Previous Period] && DimTime[Date].[Date] <= Today())
)  - I'm having issues with my DAX

 

I am trying to get the profit of Prior Year to show on a combo chart that is filtered by a slicer. 

2 Main issues: 

- The PY profit line extends into the next year and I would like it to be cut off by today.

Skorcamp_0-1646950017285.png

 

- When the slicer does not include the previous year, the measure does not account for the data and therefore ignores it. 

Skorcamp_2-1646950394345.png

 

 

 

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Skorcamp ,

 

I think ALL function in your code will make your result incorrect. Make sure you have created a relationship between DimDate table and FS table. Then use SAMEPERIODLASTYEAR function directly.

1.png

Profit PY = CALCULATE([Profit],SAMEPERIODLASTYEAR(DimDate[Date])) 

Result is as below.

2.png

 

Best Regards,
Rico Zhou

 

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

 

Hi Rico,

    I really appreciate your assistance. I have used multiple variations of the formula I provided as well as the one you suggested. To give more details from the example you have. 

As profit shows 2020, 2021 and some of 2022. As the slicer has filtered out the remaining data. I would like the PY profit to show 2019, 2020 and some of 2021 throughout the entire range of the chart in your example and it would be perfect.

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.