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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
GriRim
Frequent Visitor

MAX date of selected period keeping the year context

Hi all,

 

I gave up with Chat GPT so I'll try my luck here.

Desired result: user selects period and measure brings latest date for that period's year selected.

This measure will be used to select proper exchange rate. The rule here  -  system should select latest selected period rate, keeping year in a context.

ScenariousSelected Period2023 Rate2024 Rate2025 Rate
1Nov 2024, Dec 2024, Jan 2025, Feb 2025, Mar 2025 31/12/202431/03/2025
2Mar 2023, Apr 2024, May 202531/03/202330/04/202431/03/2025
3Feb 2024, May 2024 31/05/2024 

 

Dim Date table consists of five columns:

FINANCIAL_Date Date column

 FINANCIAL_MONTH Month number

 FINANCIAL_QTR Quarter number

 FINANCIAL_YEAR Year number

FINANCIAL_YEAR_MONTH Combination of Year and month

 

Periods will be selected on combination:  FINANCIAL_YEAR & FINANCIAL_MONTH

Can someone help me with the DAX?

This DAX brings the latested selected period (not keeping year in a contex):

 CALCULATE( MAX('Dim Date'[FINANCIAL_DATE]), ALLSELECTED('Dim Date'[FINANCIAL_YEAR_MONTH]))
 
2 ACCEPTED SOLUTIONS
bhanu_gautam
Super User
Super User

@GriRim , Try using

dax
LatestSelectedPeriodDate =
VAR SelectedYear = MAX('Dim Date'[FINANCIAL_YEAR])
RETURN
CALCULATE(
MAX('Dim Date'[FINANCIAL_DATE]),
FILTER(
ALLSELECTED('Dim Date'),
'Dim Date'[FINANCIAL_YEAR] = SelectedYear
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

DataNinja777
Super User
Super User

Hi @GriRim ,

 

To get the latest selected period while keeping the financial year context, you need to avoid using ALLSELECTED('Dim Date'[FINANCIAL_YEAR_MONTH]) alone because it removes the year context, resulting in a single max date across all selected periods. Instead, use a measure that filters the selected periods but retains the year context. The following DAX formula ensures that the latest date is picked within the same financial year as the current context:

MaxDate_PerYear = 
CALCULATE(
    MAX('Dim Date'[FINANCIAL_DATE]),
    FILTER(
        ALLSELECTED('Dim Date'),
        'Dim Date'[FINANCIAL_YEAR] = MAX('Dim Date'[FINANCIAL_YEAR])
    )
)

This measure works correctly in visuals that have FINANCIAL_YEAR in the row context. It evaluates the maximum date from the selected periods, but only for rows where the year matches the current year in context, effectively giving you the latest period date for each year based on what's selected.

 

Best regards,

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @GriRim ,

 

To get the latest selected period while keeping the financial year context, you need to avoid using ALLSELECTED('Dim Date'[FINANCIAL_YEAR_MONTH]) alone because it removes the year context, resulting in a single max date across all selected periods. Instead, use a measure that filters the selected periods but retains the year context. The following DAX formula ensures that the latest date is picked within the same financial year as the current context:

MaxDate_PerYear = 
CALCULATE(
    MAX('Dim Date'[FINANCIAL_DATE]),
    FILTER(
        ALLSELECTED('Dim Date'),
        'Dim Date'[FINANCIAL_YEAR] = MAX('Dim Date'[FINANCIAL_YEAR])
    )
)

This measure works correctly in visuals that have FINANCIAL_YEAR in the row context. It evaluates the maximum date from the selected periods, but only for rows where the year matches the current year in context, effectively giving you the latest period date for each year based on what's selected.

 

Best regards,

bhanu_gautam
Super User
Super User

@GriRim , Try using

dax
LatestSelectedPeriodDate =
VAR SelectedYear = MAX('Dim Date'[FINANCIAL_YEAR])
RETURN
CALCULATE(
MAX('Dim Date'[FINANCIAL_DATE]),
FILTER(
ALLSELECTED('Dim Date'),
'Dim Date'[FINANCIAL_YEAR] = SelectedYear
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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