March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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 East Metro | APP | G | Jun-24 | HIGH |
Sydney East Metro | APP | G | Mar-24 | MOD |
Sydney East Metro | APP | G | Dec-23 | HIGH |
Sydney East Metro | APP | G | Sep-23 | HIGH |
Sydney East Metro | APP | G | Jun-23 | MOD |
Sydney East Metro | Asur | G | Jun-24 | LOW |
Sydney East Metro | Asur | G | Mar-24 | MOD |
Sydney East Metro | Asur | G | Dec-23 | MOD |
Sydney East Metro | Asur | G | Sep-23 | MOD |
Sydney East Metro | Asur | G | Jun-23 | MOD |
Sydney East Metro | AW | G | Jun-24 | MOD |
Sydney East Metro | AW | G | Mar-24 | MOD |
Sydney East Metro | AW | G | Dec-23 | MOD |
Sydney East Metro | AW | G | Sep-23 | MOD |
Sydney East Metro | AW | G | Jun-23 | MOD |
Sydney East Metro | MAX | EO | Jun-24 | LOW |
Sydney East Metro | MAX | EO | Mar-24 | LOW |
Sydney East Metro | MAX | EO | Dec-23 | LOW |
Sydney East Metro | MAX | EO | Sep-23 | MOD |
Sydney East Metro | MAX | EO | Jun-23 | MOD |
Sydney East Metro | MCD | G | Jun-24 | MOD |
Sydney East Metro | MCD | G | Mar-24 | MOD |
Sydney East Metro | MCD | G | Dec-23 | MOD |
Sydney East Metro | MCD | G | Sep-23 | MOD |
Sydney East Metro | MCD | G | Jun-23 | MOD |
Sydney South West | Global | G | Jun-24 | LOW |
Sydney South West | Global | G | Mar-24 | LOW |
Sydney South West | Global | G | Dec-23 | LOW |
Sydney South West | Global | G | Sep-23 | LOW |
Sydney South West | Global | G | Jun-23 | LOW |
Sydney South West | Global | EO | Jun-24 | LOW |
Sydney South West | Global | EO | Mar-24 | LOW |
Sydney South West | Global | EO | Dec-23 | MOD |
Sydney South West | Global | EO | Sep-23 | LOW |
Sydney South West | Global | EO | Jun-23 | LOW |
Sydney South West | Jobs | G | Jun-24 | HIGH |
Sydney South West | Jobs | G | Mar-24 | LOW |
Sydney South West | Jobs | G | Dec-23 | MOD |
Sydney South West | Jobs | G | Sep-23 | MOD |
Sydney South West | Jobs | G | Jun-23 | LOW |
Sydney South West | Matching | G | Jun-24 | MOD |
Sydney South West | Matching | G | Mar-24 | MOD |
Sydney South West | Matching | G | Dec-23 | MOD |
Sydney South West | Matching | G | Sep-23 | MOD |
Sydney South West | Matching | G | Jun-23 | MOD |
Sydney South West | SR | G | Jun-24 | MOD |
Sydney South West | SR | G | Mar-24 | MOD |
Sydney South West | SR | G | Dec-23 | MOD |
Sydney South West | SR | G | Sep-23 | MOD |
Sydney South West | SR | G | Jun-23 | MOD |
I need to have the return outcome as below (last column). Can someone please help :). Tia.
Region | Company | Type | Period | Rating | Previous Qtr Performance |
Sydney East Metro | APP | G | Jun-24 | HIGH | MOD |
Sydney East Metro | APP | G | Mar-24 | MOD | HIGH |
Sydney East Metro | APP | G | Dec-23 | HIGH | HIGH |
Sydney East Metro | APP | G | Sep-23 | HIGH | MOD |
Sydney East Metro | APP | G | Jun-23 | MOD | N/A |
Sydney East Metro | Asur | G | Jun-24 | LOW | MOD |
Sydney East Metro | Asur | G | Mar-24 | MOD | MOD |
Sydney East Metro | Asur | G | Dec-23 | MOD | MOD |
Sydney East Metro | Asur | G | Sep-23 | MOD | MOD |
Sydney East Metro | Asur | G | Jun-23 | MOD | N/A |
Sydney East Metro | AW | G | Jun-24 | MOD | MOD |
Sydney East Metro | AW | G | Mar-24 | MOD | MOD |
Sydney East Metro | AW | G | Dec-23 | MOD | MOD |
Sydney East Metro | AW | G | Sep-23 | MOD | MOD |
Sydney East Metro | AW | G | Jun-23 | MOD | N/A |
Solved! Go to Solution.
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.
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.
Thank you, it works 🙂
@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
try this - hope it works
https://drive.google.com/file/d/1Yn5sVsys9KhycfUSqYVLFbOv3yzmFZc2/view?usp=drive_link
Approve the access request
@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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
87 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |