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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Marshmallow
Frequent Visitor

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
Impactful Individual
Impactful Individual

@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

 

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
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Top Solution Authors