Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi,
I have two tables in power bi. Table 1 is a list of customers, Table 2 has a list of sales. I want to create a new column in Table 1 that contains the most recent sale item for each customer. Can't seem to make it work with DAX.
Table 1
CUSTOMER ID | CUSTOMER NAME |
1 | James |
2 | Joe |
3 | John |
Table 2
SALE | ITEM | CUSTOMER ID | SALE DATE |
1 | Apple | 1 | 1/1/2022 |
2 | Peach | 2 | 1/2/2000 |
3 | Apple | 1 | 1/5/2001 |
4 | Banana | 3 | 8/2/2021 |
5 | Peach | 1 | 1/2/2000 |
6 | Banana | 2 | 1/8/2000 |
Cheers
Rob
Hi,
Create a relationship (Many to One and Single) from Table2 to Table1. Create a Calendar Table and a relationship (Many to One and Single) from the Sale Date of Table2 to the Date column of the Calendar Table. To your Table visual, drag the fields from Table1. Write these measures
Farthest date = max('Table2'[Sale date])
Last item bought = calculate(min('Table2'[Item]),datesbetween(Calendar[Date],[Farthest date],[Farthest date]))
Hope this helps.
User | Count |
---|---|
125 | |
106 | |
99 | |
63 | |
62 |
User | Count |
---|---|
135 | |
116 | |
101 | |
71 | |
61 |