Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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.
Scenarious | Selected Period | 2023 Rate | 2024 Rate | 2025 Rate |
1 | Nov 2024, Dec 2024, Jan 2025, Feb 2025, Mar 2025 | 31/12/2024 | 31/03/2025 | |
2 | Mar 2023, Apr 2024, May 2025 | 31/03/2023 | 30/04/2024 | 31/03/2025 |
3 | Feb 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):
Solved! Go to Solution.
@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
)
)
Proud to be a 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,
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,
@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
)
)
Proud to be a Super User! |
|
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
60 | |
58 | |
54 | |
36 | |
33 |
User | Count |
---|---|
79 | |
66 | |
45 | |
45 | |
43 |