Forum Discussion
MAX FUNCTION FROM A DATE
Hi all,
I need to create a dax mesure that retrieves P&L Sub cost and the latest budget phase based on the max wiser year or based on the filter selection
I created:
Many thanks!
I have found the solution:
Cost Recent Upd =
CALCULATE(
[Total IT Cost],
FILTER('IT Cost (KCar)','IT Cost (KCar)'[Wiser Date]=[Date Most Recent Upd]
))
Date Most Recent Upd =
CALCULATE(
MAX('IT Cost (KCar)'[Wiser Date]),
FILTER(
'IT Cost (KCar)',
CONTAINSSTRING('IT Cost (KCar)'[Budget Phase], "Upd")
)
)
Tks the others options did not retrive the results
6 Replies
- bhanu_gautam
Super User
fbittencourt ,Create a measure to get the latest Wiser Date based on the filter selection:
LastWiserDate =
VAR MaxDate = MAXX(ALLSELECTED('IT Cost (KCar)'), 'IT Cost (KCar)'[Wiser Date])
RETURN MaxDateCreate a measure to filter by budget phase and get the P&L Sub cost based on the latest Wiser Date:
DAX
P&LSubCost_LatestBudgetPhase =
VAR LatestDate = [LastWiserDate]
RETURN
CALCULATE(
SUM('IT Cost (KCar)'[P&L Sub cost]),
FILTER(
'IT Cost (KCar)',
'IT Cost (KCar)'[Wiser Date] = LatestDate &&
'IT Cost (KCar)'[Budget Phase] IN {"upd", "PMT"}
)
)- fbittencourt
Helper IV
Unfortunately the mesures rejects the filter function.
Tks for your time!
- rajendraongole1
Super User
Hi fbittencourt - can you check the below modified dax function?
P&L Sub Cost Latest =
VAR MaxYear = MAX('IT Cost (KCar)'[Wiser Year])
VAR MaxDate =
CALCULATE(
MAX('IT Cost (KCar)'[Wiser Date]),
'IT Cost (KCar)'[Wiser Year] = MaxYear
)
VAR LatestBudgetPhase =
CALCULATETABLE(
'IT Cost (KCar)',
'IT Cost (KCar)'[Wiser Date] = MaxDate,
'IT Cost (KCar)'[Wiser Year] = MaxYear,
'IT Cost (KCar)'[Budget Phase] IN {"upd", "PMT"} -- Adjust as needed
)
RETURN
CALCULATE(
SUM('IT Cost (KCar)'[P&L Sub Cost]),
LatestBudgetPhase
)If you want to filter based on user selection, replace IN {"upd", "PMT"} with a slicer reference
'IT Cost (KCar)'[Budget Phase] IN VALUES('IT Cost (KCar)'[Budget Phase])
Hope this helps.
- fbittencourt
Helper IV
Hi rajendraongole1,
Based on the table I should have the result from P&L SUb Cost, filtering ascending on wiser date, we have the 5Upd, and filtering year 2023, your mesure has no errors but is showing blank values.
Tks again for your time
- AnonymousNot applicable
Hi fbittencourt
Please provide sample data that fully covers your issue (in the form of table or pbix file) and the expected outcome based on the sample data you provided. Please remove any sensitive data in advance.
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- fbittencourt
Helper IV
I have found the solution:
Cost Recent Upd =
CALCULATE(
[Total IT Cost],
FILTER('IT Cost (KCar)','IT Cost (KCar)'[Wiser Date]=[Date Most Recent Upd]
))
Date Most Recent Upd =
CALCULATE(
MAX('IT Cost (KCar)'[Wiser Date]),
FILTER(
'IT Cost (KCar)',
CONTAINSSTRING('IT Cost (KCar)'[Budget Phase], "Upd")
)
)
Tks the others options did not retrive the results