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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join 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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.