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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
dkay84_PowerBI
Microsoft Employee
Microsoft Employee

DAX help

I am trying to calculate sales YTD (using week number) vs. sales Last Year YTD.  I can't use SAMEPERIODLASTYEAR because I have a custom FY calendar.  My data will only ever have the current FY (YTD) and the full prior FY.

 

I have a measure, "Latest Week YTD", that calculates the latest week number of the current FY.  Lets say this measure returns the number 12 currently.  

 

 

Latest Week YTD =
CALCULATE (
    MAX ( Table1[Week Number] ),
    FILTER ( ALL ( Table1[FY] ), Table1[FY] = MAX ( Table1[FY] ) )
)

I also have a measure, "Last Year", that returns the previous FY.  Lets say this measure returns the number 2016 currently:

 

Last Year =
CALCULATE ( MIN ( Table1[FY] )ALL ( Table1[FY] ) )

 

I am trying to create a measure that will dynamically calculate the sales for the previous FY using the week number returned by the Latest Week YTD measure:

 

 

Last YTD Sales =
CALCULATE (
    SUM ( Table[Sales] ),
    FILTER ( ALL ( Table[FY] ), Table[FY] = [LastYear] ),
    FILTER ( ALL ( Table[Week Number] ), Table[Week Number] <= [Latest Week YTD] )
)

 

My problem is that this last measure only returns the full amount for the entire previous FY.  If I change the last filter arguement from 

Table[Week Number] <= [Latest Week YTD] 

to

Table[Week Number] <= 12

it works fine.

 

Can someone please tell me what I am missing?

 

Thanks

 

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@dkay84_PowerBI

 

hi, With this modifcation should be work.

 

Last YTD Sales =
VAR LY = [Last Year]
VAR LW = [Latest Week YTD]
RETURN
    CALCULATE (
        SUM ( Table1[Sales] ),
        FILTER ( ALL ( Table1 ), Table1[FY] = LY && Table1[Week Number] <= LW )
    )



Lima - Peru

View solution in original post

2 REPLIES 2
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @dkay84_PowerBI,

You should create the measure using the formula @dkay84_PowerBI posted. Please feel free to ask if you have other issue.

Best Regards,
Angelia

Vvelarde
Community Champion
Community Champion

@dkay84_PowerBI

 

hi, With this modifcation should be work.

 

Last YTD Sales =
VAR LY = [Last Year]
VAR LW = [Latest Week YTD]
RETURN
    CALCULATE (
        SUM ( Table1[Sales] ),
        FILTER ( ALL ( Table1 ), Table1[FY] = LY && Table1[Week Number] <= LW )
    )



Lima - Peru

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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