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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Thiagops
Helper II
Helper II

Column with date of last purchase

Good morning,
I have 02 tables (One with sales and another with customers).

I need to include a column in the customer table with the date of the last purchase made by him
- The column I have in the 2 tables is CLI_CODIGO
- The column that has the date of sale is NS_DATA_EMISSAO

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Thiagops 
Please try

Last Purchase Date =
MAXX ( RELATEDTABLE ( Sales ), Sales[NS_DATA_EMISSAO] )

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Thiagops 
Please try

Last Purchase Date =
MAXX ( RELATEDTABLE ( Sales ), Sales[NS_DATA_EMISSAO] )
jaweher899
Super User
Super User

You can achieve this by using a calculated column in the customer table that uses the MAX function to retrieve the latest date of purchase for each customer. Here's the DAX code for the calculated column:

Last Purchase Date = CALCULATE(MAX(Sales[NS_DATA_EMISSAO]), FILTER(Sales, Sales[CLI_CODIGO] = Customers[CLI_CODIGO]))

In this code, "Sales" is the table with sales data, "Customers" is the table with customer data, "NS_DATA_EMISSAO" is the date of sale column in the Sales table, and "CLI_CODIGO" is the column that links the two tables. The CALCULATE function evaluates an expression in a modified filter context, and the FILTER function returns a table with only the rows that meet the specified criteria. In this case, the FILTER function is used to filter the Sales table to only include the sales for the customer in the current row of the customer table. The MAX function is then used to find the maximum value of the NS_DATA_EMISSAO column in the filtered Sales table, which will be the latest date of purchase for the customer.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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