Forum Discussion

Marshmallow's avatar
Marshmallow
Helper II
1 year ago
Solved

return value (text format) for previous qtr

Hi, I need help with dax formula to return previous period with this messy data that I have. Can someone please help? Below is my data (sample)   Region Company Type Period Rating Sydney...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Marshmallow ,

    Please try this way:
    First use this DAX to create a calculated column:

    RANK = 
    VAR _Region = [Region]
    VAR _Company = [Company]
    VAR _Type = [Type]
    RETURN
    RANKX(
        FILTER(
            ALL('Table'),
            'Table'[Region] = _Region && 'Table'[Company] = _Company && 'Table'[Type] = _Type
        ),
        'Table'[Period],
        ,
        DESC,
        Dense
    )

    Then use this DAX to create another calculated column:

    Previous Qtr = 
    VAR _Region = [Region]
    VAR _Company = [Company]
    VAR _Type = [Type]
    VAR _Rank = [RANK]
    RETURN
    CALCULATE(
        MAX('Table'[Rating]),
        ALL('Table'),
        'Table'[Region] = _Region && 'Table'[Company] = _Company && 'Table'[Type] = _Type && 'Table'[RANK] = _Rank + 1
    )

    And the final output is as below:


    Best Regards,
    Dino Tao
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.