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

Calculate YTD CY and PY Sales based on Year Selected

Hello Community,
 
I have a pretty basic scenario for which I am unable to figure out how to approach the solution. I need to show the CY sales and PY sales based on Year Selected.
 
For example,
If I select Year = 2019 in a filter, then CY Should be 2019 and PY should be 2018
If I select Year = 2018, then CY should be 2018 and PY should be 2017.
Below is the image how sample data looks like
 
Image.PNGSample Data
 
So, here what I have done so far

Created a new table with this formula

Table = VALUES(Sheet2[Year])

 

Added Table[year] in the slicer, created the measures in "Sheet2".

Selected year = SELECTEDVALUE('Table'[Year])\

CY = CALCULATE(SUM(Sheet2[Sales]),FILTER(ALL(Sheet2),[Year]=[Selected year]))

PY = 
CALCULATE(SUM(Sheet2[Sales]),FILTER(ALL(Sheet2),[Year]=[Selected year]-1))

Every thing is working fine.

 

Now I have to calculate YTD Sales for CY and PY based on year/month selected.

 

Thanks,

James Arthur

 

 

 

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @Anonymous, 

 

For your requirement, you can use SAMEPERIODLASTYEAR() and TOTALYTD() function. According to your Sample data, I create measures: 

 

YTD for CY = TOTALYTD(SUM(Sheet2[Sales]),'Table'[Date])

YTD for PY = CALCULATE(SUM(Sheet2[Sales]),SAMEPERIODLASTYEAR('Table'[Date]))

 

w1.PNGw2.PNGw3.PNG

 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-qiuyu-msft
Community Support
Community Support

Hi @Anonymous, 

 

For your requirement, you can use SAMEPERIODLASTYEAR() and TOTALYTD() function. According to your Sample data, I create measures: 

 

YTD for CY = TOTALYTD(SUM(Sheet2[Sales]),'Table'[Date])

YTD for PY = CALCULATE(SUM(Sheet2[Sales]),SAMEPERIODLASTYEAR('Table'[Date]))

 

w1.PNGw2.PNGw3.PNG

 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.