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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
JLarkin
Frequent Visitor

Accumulated YTD that ignores filter

Hi all, 

 

I'm looking to include a column in a table which includes sales YTD, in a monthly view. 
E.g. If I filter by August, it includes sales YTD for Jan-Aug.

This is the current formula:

Total Sales YTD = 

VAR RetVal = 
CALCULATE(
    SUM('Revenue'[Sales Booked Amt - at Plan Rt]),
    ALL('DATE_DIM'),
    VALUES(DATE_DIM[YR_NBR])
)

RETURN
    IF(
        MAX('DATE_DIM'[MNTH_NBR]) <= SELECTEDVALUE(DATE_DIM[MNTH_NBR]),
        RetVal)


The issue I have is that to include a YTD calculation, I need to exclude the month filter to have Jan-Aug.
However, this then includes September and October data. Instead, I need the range to max at selected month value

Screenshot 2022-10-15 143935.png

Does anyone know how I can recode this to have it exclude anything after SELECTED VALUE of the month filter?
Unfortunately, I can't create another table as I need drill down capabilities.

Thanks!

2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @JLarkin 

Please try

Total Sales YTD =
CALCULATE (
    SUM ( 'Revenue'[Sales Booked Amt - at Plan Rt] ),
    FILTER (
        ALL ( 'DATE_DIM' ),
        'DATE_DIM'[Month Number] <= MAX ( 'DATE_DIM'[Month Number] )
    ),
    VALUES ( DATE_DIM[YR_NBR] )
)

View solution in original post

Hi @JLarkin 

please try

Sales YTD PY = 
CALCULATE(
    SUM('Revenue'[Sales Booked Amt - at Plan Rt]),
    FILTER(
        ALL('DATE_DIM'),
        'DATE_DIM'[MNTH_NBR] <= MAX('DATE_DIM'[MNTH_NBR])
            && 'DATE_DIM'[YR_NBR] = (MAX('DATE_DIM'[YR_NBR])-1)
    )
)

View solution in original post

5 REPLIES 5
JLarkin
Frequent Visitor

Again, thank you very much @tamerj1 !

JLarkin
Frequent Visitor

Hi @tamerj1,

This worked! Thank you very much for your help


tamerj1
Super User
Super User

Hi @JLarkin 

Please try

Total Sales YTD =
CALCULATE (
    SUM ( 'Revenue'[Sales Booked Amt - at Plan Rt] ),
    FILTER (
        ALL ( 'DATE_DIM' ),
        'DATE_DIM'[Month Number] <= MAX ( 'DATE_DIM'[Month Number] )
    ),
    VALUES ( DATE_DIM[YR_NBR] )
)

Hi @tamerj1, and others,


I was wondering if you could perhaps assist me with a new and similar measure.
Rather than just a Total Sales YTD, I'm looking to have a Sales YTD of last year - where we were this time last year.

Here is the code I have

 

Sales YTD PY = 
CALCULATE(
    SUM('Revenue'[Sales Booked Amt - at Plan Rt]),
    FILTER(
        ALL('DATE_DIM'),
        'DATE_DIM'[MNTH_NBR] <= MAX('DATE_DIM'[MNTH_NBR])
            && 'DATE_DIM'[YR_NBR] = (MAX('DATE_DIM'[YR_NBR])-1)
    ),
    VALUES(DATE_DIM[YR_NBR])
)

 

This works to an extent, in the sense that if I select 2021 and 2022 in the filters, it will show 2021 data.

But this isn't practical, as it changes the other figures. I would need it to show 2021's figures when 2022 is selected only.

 

Thank you in advance!

Hi @JLarkin 

please try

Sales YTD PY = 
CALCULATE(
    SUM('Revenue'[Sales Booked Amt - at Plan Rt]),
    FILTER(
        ALL('DATE_DIM'),
        'DATE_DIM'[MNTH_NBR] <= MAX('DATE_DIM'[MNTH_NBR])
            && 'DATE_DIM'[YR_NBR] = (MAX('DATE_DIM'[YR_NBR])-1)
    )
)

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric Community.