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 August 31st. Request your voucher.

Reply
RachaelB
Frequent Visitor

RANKX and SAMEPERIODLASTYEAR

Hi all,

 

I'm new to the forum and would appreciate some help.

 

I have Filters on all pages, that the end user can choose for either date range, and/or segment. I have created a RANKX measure, which uses those filters.

 

I want to see which individuals are costing the most in repair costs, by segment, for the date period chosen. (The DateKey is used as there are a few different date fields in the model). This is the DAX I've written to do that:

 

Individual Ranked Total Repair Costs =
CALCULATE(
    RANKX(ALL('Repair Data'[Individual Name]), [Total Repair Costs],,DESC),
        ALLSELECTED('Repair Data'[Segment]),
            ALLSELECTED('Calendar'[DateKey]))
 
It gives me the results I expect.
 
I want to compare this to the SAMEPERIODLASTYEAR, however when I try to use SAMEPERIODLASTYEAR, it's showing the previous year's costs for those ranking in the original timescale rather than giving me new individuals ranked for the previous period...
 
Individual Ranked Total Repair Costs LY =
CALCULATE(
    RANKX(ALL('Repair Data'[Individual Name]), [Total Repair Costs],,DESC),
        ALLSELECTED('Repair Data'[Segment]),
        ALL('Calendar'[DateKey]),
                      SAMEPERIODLASTYEAR('Calendar'[DateKey]))
 
Any thoughts?? Thank you all!
1 ACCEPTED SOLUTION

Try

Individual Ranked Total Repair Costs LY =
CALCULATE (
    RANKX ( ALL ( 'Repair Data'[Individual Name] ), [Total Repair Costs],, DESC ),
    ALLSELECTED ( 'Repair Data'[Segment] ),
    ALLSELECTED ( 'Calendar' ),
    SAMEPERIODLASTYEAR ( 'Calendar'[DateKey] )
)

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

What is the definition of [Total Repair Costs]? Is that manipulating the filter context ?

Thanks for responding!

 

Total Repair Costs is using a filter in it's DAX formula as I only want to include certain statuses of repairs. It's a measure that I want to display in a graph. So the graph will show the top ranked individuals in the X axis, with the costs showing as the size of the bar.

 

Total Repair Costs =

CALCULATE(
    SUM('Repair Data'[Repairs Total]),
        USERELATIONSHIP('Repairs Data'[Date1],'Calendar'[DateKey]),
        FILTER('Repair Data','Repair Data'[Repairs Completed]="Closed")
)
 
 
 
(FYI, Repairs Total is a field in dataset and not calculated in anyway in pbix)

Try

Individual Ranked Total Repair Costs LY =
CALCULATE (
    RANKX ( ALL ( 'Repair Data'[Individual Name] ), [Total Repair Costs],, DESC ),
    ALLSELECTED ( 'Repair Data'[Segment] ),
    ALLSELECTED ( 'Calendar' ),
    SAMEPERIODLASTYEAR ( 'Calendar'[DateKey] )
)

That's great, thank you so much!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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