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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Finding the job title number of each salesperson in the previous month

Hi all,

 

I have the example (not real) data below, with the aim to find the job title number of each salesperson in the previous month

 

In the table below, I have assigned the title number: 'Junior Sales Associate' as 1 and 'Senior Sales Associate' as 2;

and the salesperson number: Salesperson 'A' as 1 and 'B' as 2

 

Now I want to create a calculated column called 'Last Month Title Number', i.e. the title number of EACH salesperson in the precious month. I tried the DAX below but returns blank:

 

Last Month Title Number =
VAR LastMonth = MAXX(FILTER('Salesperson and commission','Salesperson and commission'[Month]<EARLIER('Salesperson and commission'[Month])),'Salesperson and commission'[Month])
VAR Salesperson = MAXX(FILTER('Salesperson and commission','Salesperson and commission'[Salesperson number]=earlier('Salesperson and commission'[Salesperson number])),'Salesperson and commission'[Salesperson number])
return
CALCULATE(sum('Salesperson and commission'[Title Number]),'Salesperson and commission'[Month]=LastMonth,'Salesperson and commission'[Salesperson number]=Salesperson)

 

SalespersonMonthComission ($)TitleTitle NumberSalesperson number
A2020/1/313000Junior Sales Associate11
A2020/2/291000Senior Sales Associate21
A2020/3/312000Senior Sales Associate21
B2020/1/317000Junior Sales Associate12
B2020/2/296000Junior Sales Associate12
B2020/3/319000Senior Sales Associate22

 

How should I revise the DAX? Thanks a lot for your help in advance!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

This is the code that gets you the prev month's title number. This should be fast on big tables as it does not use CALCULATE.

[Prev Tittle Number] = // calculated column
var __salespersonNumber = T[Salesperson Number]
var __currentDate = T[Month] // this must be the date data type
var __prevTitleNumber =
	MAXX(
		topn(1,
			filter(
				T,
				T[Salesperson Number] = __salespersonNumber,
				T[Month] < __currentDate
			),
			T[Month],
			DESC
		),
		T[Title Number]
	)
return
	__prevTitleNumber

 

Best

D

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

This is the code that gets you the prev month's title number. This should be fast on big tables as it does not use CALCULATE.

[Prev Tittle Number] = // calculated column
var __salespersonNumber = T[Salesperson Number]
var __currentDate = T[Month] // this must be the date data type
var __prevTitleNumber =
	MAXX(
		topn(1,
			filter(
				T,
				T[Salesperson Number] = __salespersonNumber,
				T[Month] < __currentDate
			),
			T[Month],
			DESC
		),
		T[Title Number]
	)
return
	__prevTitleNumber

 

Best

D

nandukrishnavs
Community Champion
Community Champion

@Anonymous 

 

Try this DAX

 

 

Previous Title = 
var _sPerson= CALCULATE(SELECTEDVALUE('Table'[Salesperson]))
var _smonth= CALCULATE(SELECTEDVALUE('Table'[Month]))
var _previousTitle= LOOKUPVALUE('Table'[Title Number],'Table'[Month],EOMONTH(_smonth,-1),'Table'[Salesperson],_sPerson)
return _previousTitle

 

 

myout.JPG

 

Since this is a data preparation activity, I would recommend you to work on Edit Query.

Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.