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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TSI
Advocate I
Advocate I

Previous Month Value (return Text)

Hi Community,

 

I have a table of employee IDs and their Pay Grades each month. 

I'm trying to create a new column 'Previous Month' which would show me the Pay Grade from the month before. 

Previous month pay grade.jpg

 

 

 

 

 

 

 

 

 

 

So, example for Employee ID 100, for 1/1/2019, it would show F.

 

Would anyone know how to do this? Most reference material show SUMX calculations for previous month's numbers, but not for text. 

 

Thank you!

 

Best regards,

Kim

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@TSI try following measure

 

Prev Pay Grade = 
VAR __prevDate = 
CALCULATE( 
    MAX( 'Table'[Calendar Date] ), 
    FILTER( 
        ALLEXCEPT( 'Table', 'Table'[Employee ID] ),  
        'Table'[Calendar Date] < MAX( 'Table'[Calendar Date] )
    )
)
RETURN
    CALCULATE( MAX( 'Table'[Pay Grade] ), ALLEXCEPT( 'Table', 'Table'[Employee ID] ), 'Table'[Calendar Date] = __prevDate ) 


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
parry2k
Super User
Super User

@_Kevin_ Thanks for the feedback. Glad you find the solution useful for your use case. 

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@TSI try following measure

 

Prev Pay Grade = 
VAR __prevDate = 
CALCULATE( 
    MAX( 'Table'[Calendar Date] ), 
    FILTER( 
        ALLEXCEPT( 'Table', 'Table'[Employee ID] ),  
        'Table'[Calendar Date] < MAX( 'Table'[Calendar Date] )
    )
)
RETURN
    CALCULATE( MAX( 'Table'[Pay Grade] ), ALLEXCEPT( 'Table', 'Table'[Employee ID] ), 'Table'[Calendar Date] = __prevDate ) 


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks @parry2k . I barely have any joy on this forum but you nailed three years ago what I needed urgently today. Great response.

Anonymous
Not applicable

Hi there @parry2k 

 

I am trying to do the same thing as previous user but it's not working for me and can't work out why.

 

My data is below

'Prev salary grade' is the dax calculated column.

As you can see it should return 6B until the report date is 30 Nov 2019 and then should start returning 6A. Instead it always returns 6A.

 

Report DateDanone IDSalary GradePrev Salary Grade
Monday, 31 December 20181236B6A
Thursday, 31 January 20191236B6A
Thursday, 28 February 20191236B6A
Sunday, 31 March 20191236B6A
Tuesday, 30 April 20191236B6A
Friday, 31 May 20191236B6A
Sunday, 30 June 20191236B6A
Wednesday, 31 July 20191236B6A
Saturday, 31 August 20191236B6A
Monday, 30 September 20191236B6A
Thursday, 31 October 20191236A6A
Saturday, 30 November 20191236A6A
Tuesday, 31 December 20191236A6A
Friday, 31 January 20201236A6A
Saturday, 29 February 20201236A6A
Tuesday, 31 March 20201236A6A
Thursday, 30 April 20201236A6A
Sunday, 31 May 20201236A6A

 

Formula

 

Prev Salary Grade =
VAR __prevDate =
CALCULATE(
MAX( 'Promotions'[Report Date] ),
FILTER(
ALLEXCEPT( Promotions, Promotions[Danone ID] ),
Promotions[Report Date] < MAX( Promotions[Report Date] )
)
)
RETURN
CALCULATE( MAX( Promotions[Salary Grade] ), ALLEXCEPT( Promotions, Promotions[Danone ID]), Promotions[Report Date]= __prevDate )
 
Any help much appreciated - I have been going round and round in circles for longer than I care to admit!!

How would you do this if it was needed as a new column and not a measure? If I need a new column with the value each ID had the previous month what would be the best way to do it? The value is not numerical.

 

Hi @parry2k 

 

Thank you so much for the solution, it worked like a charm.

 

Appreciate the Measure, it saved me from creating 4 columns! (that's what it took when I tried to use Lookupvalue).

Your measure is definitely superior.

 

Best regards,

Kim 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.