Forum Discussion

fbittencourt's avatar
fbittencourt
Icon for Helper IV rankHelper IV
1 year ago
Solved

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: 

Lastdate =
VAR MaxDate = MAXX(FILTER('IT Cost (KCar)', 'IT Cost (KCar)'[Wiser Date]),'IT Cost (KCar)'[Wiser Date])
RETURN  MaxDate
 I need to add or combine another DAX To try to filter it
 
 I need to filter for example " upd" or "PMT" from budget phase, and have the P&L Sub cost , based on the max date from a year selection
 

 

 

 

 

 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

  • 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 MaxDate

     

    Create 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's avatar
      fbittencourt
      Icon for Helper IV rankHelper IV

      Unfortunately the mesures rejects the filter function.

       

      Tks for your time!

       

       

  • 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's avatar
      fbittencourt
      Icon for Helper IV rankHelper 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

       

       

       

       

       

  • Anonymous's avatar
    Anonymous
    Not 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's avatar
      fbittencourt
      Icon for Helper IV rankHelper 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