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
Syzmik
Frequent Visitor

Current and Previous Year Cumulative

Hi,

 

I'm wanting to display current year (last 12 calendar months) and previous year (months 24-13) cumulative job count on a line graph to visualise the difference in jobs YOY.

I can get monthly numbers as a SUM to appear per month with SAMEPERIOSLASTYEAR, but struggling producing a cumulative total with similar time logic. This is a sample set of data I have. 

• Jobs represents No. jobs for the month
• CY is the cumulative total for the previous 12 months that I've added together in Excel for reference

• Last year is same logic as above for months 24-13 from current date

• Haven't included Apr-24 in the CY calculation as wanting this for calendar months

 

Mth/Yr     Jobs     CY    Last year 

Apr-22999 999
May-221149 2148
Jun-22856 3004
Jul-22925 3929
Aug-221036 4965
Sep-221264 6229
Oct-22994 7223
Nov-221258 8481
Dec-221001 9482
Jan-23946 10428
Feb-23718 11146
Mar-23889 12035
Apr-23763763 
May-238821645 
Jun-2310292674 
Jul-238723546 
Aug-2311154661 
Sep-239565617 
Oct-238526469 
Nov-238647333 
Dec-236637996 
Jan-246558651 
Feb-247019352 
Mar-245119863 
Apr-24324  

 

I'm trying to get it into a format like

Month    CY    LY 

Apr763999
May16452148
Jun26743004
Jul35463929
Aug46614965
Sep56176229
Oct64697223
Nov73338481
Dec79969482
Jan865110428
Feb935211146
Mar986312035
4 REPLIES 4
v-xinruzhu-msft
Community Support
Community Support

Hi, 

Thanks for the solution @Ashish_Mathur  and @amitchandak  provided, i want to offer some more information for user to refer to.

hello @Syzmik , you can refer to the following solution.

1.There is no relationship between date table and fact table.

2.Create the followign measures.

CY =
VAR a =
    MAXX ( ALLSELECTED ( 'Table 2' ), [Date] )
VAR b =
    EOMONTH ( a, -13 ) + 1
VAR c =
    EOMONTH ( a, -1 )
RETURN
    IF (
        MAX ( 'Table'[Mth/Yr] ) >= b
            && MAX ( 'Table'[Mth/Yr] ) <= c,
        CALCULATE (
            SUM ( 'Table'[Jobs] ),
            ALL ( 'Table' ),
            'Table'[Mth/Yr] <= MAX ( 'Table'[Mth/Yr] ),
            'Table'[Mth/Yr] >= b,
            'Table'[Mth/Yr] <= c
        )
    )
LY =
VAR a =
    MAXX ( ALLSELECTED ( 'Table 2' ), [Date] )
VAR b =
    EOMONTH ( a, -25 ) + 1
VAR c =
    EOMONTH ( a, -13 )
RETURN
    IF (
        MAX ( 'Table'[Mth/Yr] ) >= b
            && MAX ( 'Table'[Mth/Yr] ) <= c,
        CALCULATE (
            SUM ( 'Table'[Jobs] ),
            ALL ( 'Table' ),
            'Table'[Mth/Yr] <= MAX ( 'Table'[Mth/Yr] ),
            'Table'[Mth/Yr] >= b,
            'Table'[Mth/Yr] <= c
        )
    )

Output

vxinruzhumsft_0-1713771588727.png

 

vxinruzhumsft_1-1713771596253.png

Best Regards!

Yolo Zhu

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

 

 

Syzmik
Frequent Visitor

Thanks for the replies.

 

I ideally want to be able to use a page level date slicer to affect this. For example, Last 1 year should result in selections from April 2023 - March 2024 for CY, and April 2022 - March 2023. Next month (May), I'd need the calculations to move forward a month (May - April).

 

I'm assuming the "31/3" logic in the forumlas is hard-coding the date to always display March - April?

Ashish_Mathur
Super User
Super User

HI,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1713496223174.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@Syzmik , I think you need YTD based on March as the end of the year

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"3/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"3/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

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.