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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.