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)

 

RegionCompanyTypePeriodRating
Sydney East MetroAPPGJun-24HIGH
Sydney East MetroAPPGMar-24MOD
Sydney East MetroAPPGDec-23HIGH
Sydney East MetroAPPGSep-23HIGH
Sydney East MetroAPPGJun-23MOD
Sydney East MetroAsurGJun-24LOW
Sydney East MetroAsurGMar-24MOD
Sydney East MetroAsurGDec-23MOD
Sydney East MetroAsurGSep-23MOD
Sydney East MetroAsurGJun-23MOD
Sydney East MetroAWGJun-24MOD
Sydney East MetroAWGMar-24MOD
Sydney East MetroAWGDec-23MOD
Sydney East MetroAWGSep-23MOD
Sydney East MetroAWGJun-23MOD
Sydney East MetroMAXEOJun-24LOW
Sydney East MetroMAXEOMar-24LOW
Sydney East MetroMAXEODec-23LOW
Sydney East MetroMAXEOSep-23MOD
Sydney East MetroMAXEOJun-23MOD
Sydney East MetroMCDGJun-24MOD
Sydney East MetroMCDGMar-24MOD
Sydney East MetroMCDGDec-23MOD
Sydney East MetroMCDGSep-23MOD
Sydney East MetroMCDGJun-23MOD
Sydney South WestGlobalGJun-24LOW
Sydney South WestGlobalGMar-24LOW
Sydney South WestGlobalGDec-23LOW
Sydney South WestGlobalGSep-23LOW
Sydney South WestGlobalGJun-23LOW
Sydney South WestGlobalEOJun-24LOW
Sydney South WestGlobalEOMar-24LOW
Sydney South WestGlobalEODec-23MOD
Sydney South WestGlobalEOSep-23LOW
Sydney South WestGlobalEOJun-23LOW
Sydney South WestJobsGJun-24HIGH
Sydney South WestJobsGMar-24LOW
Sydney South WestJobsGDec-23MOD
Sydney South WestJobsGSep-23MOD
Sydney South WestJobsGJun-23LOW
Sydney South WestMatchingGJun-24MOD
Sydney South WestMatchingGMar-24MOD
Sydney South WestMatchingGDec-23MOD
Sydney South WestMatchingGSep-23MOD
Sydney South WestMatchingGJun-23MOD
Sydney South WestSRGJun-24MOD
Sydney South WestSRGMar-24MOD
Sydney South WestSRGDec-23MOD
Sydney South WestSRGSep-23MOD
Sydney South WestSRGJun-23MOD

 

I need to have the return outcome as below (last column). Can someone please help :). Tia.

RegionCompanyTypePeriodRatingPrevious Qtr Performance
Sydney East MetroAPPGJun-24HIGHMOD
Sydney East MetroAPPGMar-24MODHIGH
Sydney East MetroAPPGDec-23HIGHHIGH
Sydney East MetroAPPGSep-23HIGHMOD
Sydney East MetroAPPGJun-23MODN/A
Sydney East MetroAsurGJun-24LOWMOD
Sydney East MetroAsurGMar-24MODMOD
Sydney East MetroAsurGDec-23MODMOD
Sydney East MetroAsurGSep-23MODMOD
Sydney East MetroAsurGJun-23MODN/A
Sydney East MetroAWGJun-24MODMOD
Sydney East MetroAWGMar-24MODMOD
Sydney East MetroAWGDec-23MODMOD
Sydney East MetroAWGSep-23MODMOD
Sydney East MetroAWGJun-23MODN/A
  • 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.

9 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.

    • Marshmallow's avatar
      Marshmallow
      Helper II

      can you please create it in the power bi and send the file so i can follow it through? i have issue creating the date too

    • Marshmallow's avatar
      Marshmallow
      Helper II

      I have never shared a file here ğŸ¤”. How do I go about it?

      • Kedar_Pande's avatar
        Kedar_Pande
        Super User

        upload the file to google drive and share the link here