Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dax for Max Month

Hai All, Please help me to solve this issue
Requirement: By default, I want o show the max month based on the table but if the user selects any year month slicer that should display so I created a measure that is not showing the maximum month by default based on my data.

This is data model 

 


June is the max month based on the data 

But based on this measure this is showing previous month and year 
Note : Both are in date type only 
please help me to achieve this 
Thanks 

 

 

  • Because your field [Year Month Name] is text, MAX is looking at it alphabetically where 2022-May is > 2022-June:

     

    Year Month Name
    2022-April
    2022-August
    2022-December
    2022-February
    2022-January
    2022-July
    2022-June
    2022-March
    2022-May
    2022-November
    2022-October
    2022-September

     

    Try a measure like this.

    _Max Month = 
    VAR _Date = MAX('Calendar'[Date])
    RETURN  CALCULATE(MAX('Calendar'[Year Month Name]),'Calendar'[Date]=_Date)

1 Reply

  • Because your field [Year Month Name] is text, MAX is looking at it alphabetically where 2022-May is > 2022-June:

     

    Year Month Name
    2022-April
    2022-August
    2022-December
    2022-February
    2022-January
    2022-July
    2022-June
    2022-March
    2022-May
    2022-November
    2022-October
    2022-September

     

    Try a measure like this.

    _Max Month = 
    VAR _Date = MAX('Calendar'[Date])
    RETURN  CALCULATE(MAX('Calendar'[Year Month Name]),'Calendar'[Date]=_Date)