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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
dexter2424
Helper I
Helper I

Cumulative SamePeriodLastYear by category

Hi, 

I'm facing an issue in the last 3 days. I thought I can solve it, but no luck. 

 

I have a measure with LY Amount:

 

LY Amount = CALCULATE([CY Amount],SAMEPERIODLASTYEAR(vw_Prem_ToO_ID[Date]),ALL(vw_Prem_ToO_ID[Date]))

 

vw_prem_toO_ID is my calendar, I know, it's a stupid name. 
I calculate the LY Amount from CY Amount. 
(This is working fine)
I have a slicer, and once I slide it, it's also work fine.

The issue I have, when I try to calculate the cumulative value of the period. 
For example, if I select period from 1/Jan/2020 till 1/May/2020 The first date amount should be 1st of Jan, and the last added to the cumulative is 1st of May. 
This is working in CY Amount:

 

Cumulative CY Amount = 
IF(
    MIN(vw_Prem_ToO_ID[Date]) <= CALCULATE(MAX(vw_Prem_ToO_ID[Date]),ALL(vw_Prem_ToO_ID)),
    CALCULATE(([CY Amount]),FILTER(ALLSELECTED(vw_Prem_ToO_ID),vw_Prem_ToO_ID[Date] <= MAX(vw_Prem_ToO_ID[Date])),VALUES(TradeTable[TradeCategory])))​

(The TradeCategory just added to split by category in a linechart later)
This is also working fine with the "CY Amount", but not working with the PY Amount. 
I have tried almost everything. 
I have checked many code, tried in different ways, but The results I got: empty, LY Amount (not the cumulative), Sum of the LY Amount.
I would like to have it in Month split like the CY.
May it's messy, but If you know anything would be helpful, I would appreciate.

Cumulative LY Amount= 
var MinDate = MIN(vw_Prem_ToO_ID[Date])
var MaxDate = MAX(vw_Prem_ToO_ID[Date])
var PYearBottom = DATE(YEAR(MinDate)-1,MONTH(MinDate),DAY(MinDate))
var PYearTop = DATE(YEAR(MaxDate)-1,MONTH(MaxDate),DAY(MaxDate))
return
       /*IF(
    PYearBottom <= CALCULATE(MaxDate,ALL(vw_Prem_ToO_ID)),
    CALCULATE(([CY Amount]),FILTER(ALLSELECTED(vw_Prem_ToO_ID),PYearBottom <= PYearTop),VALUES(Trade[TradeCategory])))*/

    
    ---IF(PYearBottom <= CALCULATE(PYearTop,ALL(vw_Prem_ToO_ID)),
    --- CALCULATE([CY GWP],FILTER(ALLSELECTED(vw_Prem_ToO_ID),vw_Prem_ToO_ID[Date] <= PYearTop)
    ---))

    ---CALCULATE([CY Amount],SAMEPERIODLASTYEAR(vw_Prem_ToO_ID[Date]))

    
    CALCULATE([LY Amount],FILTER(ALLSELECTED(vw_Prem_ToO_ID),vw_Prem_ToO_ID[Date] <= MAX(vw_Prem_ToO_ID[Date])))​


This are and the combination of these I have tried.
Thanks, Denes

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@dexter2424 , Not very clear. Have to try formula like?

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@dexter2424 , Not very clear. Have to try formula like?

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

No, I have missed this, but helped me a lot! 

Thank You!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.