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
JlmillerRedmond
Microsoft Employee
Microsoft Employee

Adding A calculated Column to Determine the Last Month of the Year in Which a Sale Occurs

I have annual sales data pulled into an Excel Power Pivot and connected to a date table that includes a serial number for each month of the year (to eliminate the need for date math).  Data includes a line for each sale to a customer over the course of the year, which can mean more than one line per customer in a given month.

 

For each customer, I need to determine the last month during the year in which a customer made a purchase.  I'm currently using the following formula: 

=MAXX( FILTER( ALL(SalesTable), SalesTable[Customer] = Earlier(SalesTable[Customer] ,SalesTable[MoSerialNo])

NOTE:  there are other fields involved like product type that use the same parameter = earlier(parameter) form.

 

For customers with only one purchase in a month, this always produces the correct results.  But for customers with more than one purchase in a month, it produces two answers; the month in which the sale occurs and the last month in which a sale occurs.  This creates issues in extracting the data as there should be a single value for the last month in which a customer makes a purchase.

 

How can I either modify this formula, use another function, or create another field that will produce one answer (the maximum month serial number) for all instances of a customer that are in the sales data?

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

You may be able to use something like this...

jgeddes_0-1737063981893.png

Calculated Column 

Last Month = 
var _cust = 
'Table'[Customer]
Return
MAXX(
    FILTER(ALL('Table'), [Customer] = _cust),
    'Table'[Month]
)

Result

jgeddes_1-1737064027848.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
jgeddes
Super User
Super User

You may be able to use something like this...

jgeddes_0-1737063981893.png

Calculated Column 

Last Month = 
var _cust = 
'Table'[Customer]
Return
MAXX(
    FILTER(ALL('Table'), [Customer] = _cust),
    'Table'[Month]
)

Result

jgeddes_1-1737064027848.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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.