Forum Discussion

nmhung49's avatar
nmhung49
Icon for Helper II rankHelper II
1 year ago
Solved

Age Calculation in DAX Incorrect for Previous Months/Years

I have created a measure to calculate age_week, but it only returns the correct result based on the current day (TODAY()). When I select a previous month or year, the calculation becomes incorrect. ...
  • Khushidesai0109's avatar
    1 year ago

    Hiiii nmhung49 

    Age_Week =
    VAR SelectedDate = MAX('Date'[Date]) -- Get the latest date in the selected time period
    VAR StartDate = SELECTEDVALUE('YourTable'[Start_Date]) -- Replace with your actual date column
    VAR AgeInDays = DATEDIFF(StartDate, SelectedDate, DAY)
    VAR AgeInWeeks = DIVIDE(AgeInDays, 7)

    RETURN AgeInWeeks

     

     

    If this helps, I would appreciate your KUDOS!
    Did I answer your question? Mark my post as a solution!