Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Marshmallow
Helper I
Helper I

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
1 ACCEPTED SOLUTION
v-junyant-msft
Community Support
Community Support

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
)

vjunyantmsft_0-1727838885463.png

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:

vjunyantmsft_2-1727839005518.png


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.

View solution in original post

9 REPLIES 9
v-junyant-msft
Community Support
Community Support

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
)

vjunyantmsft_0-1727838885463.png

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:

vjunyantmsft_2-1727839005518.png


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.

Thank you, it works 🙂

Kedar_Pande
Resident Rockstar
Resident Rockstar

@MarshmallowCould you share the file with me? I'll design it and send it back to you.

I have never shared a file here 🤔. How do I go about it?

upload the file to google drive and share the link here

Approve the access request

amitchandak
Super User
Super User

@Marshmallow , I would prefer to create date using period 

 

Date = datevalue("01-" &[Period])

 

I can join this date with date of date table and use time intelligence

 

Power BI — Qtr on Qtr with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-qtd-questions-time-intelligence-2-5-d842063da839
https://www.youtube.com/watch?v=8-TlVx7P0A0

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.