Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have a fact table of sales and I need to get 2 new columns, wich will display Previous date of purchase and Previous sales status (both red in the table below).
I'm trying to get same results as with using lag/window function in SQL ( lag(date_of_purchase) over (partition by month_of_sale, customer, product order by date_of_purchase).
Also, the problem is, I no longer can edit Query (the table in database no longer exists)..
month of sale | customer | product | sales status | date of purchase | previous date of purchase | previous sales status |
Dec-16 | john | A | booked | 01-12-16 | null | null |
Dec-16 | john | A | booked | 20-12-16 | 01-12-16 | booked |
Dec-16 | alicia | A | paid | 01-12-16 | null | null |
Jan-17 | john | Ck111 | booked | 01-01-17 | null | null |
Jan-17 | john | Ck111 | paid | 13-01-17 | 01-01-17 | booked |
Jan-17 | john | A | booked | 01-01-17 | null | null |
Jan-17 | john | A | booked | 03-01-17 | 01-01-17 | booked |
Jan-17 | alicia | Ck111 | booked | 01-01-17 | null | null |
Jan-17 | alicia | Ck111 | paid | 13-01-17 | 01-01-17 | booked |
Jan-17 | alicia | Ck111 | paid | 20-01-17 | 13-01-17 | paid |
I've been trying to use calculate function with filters, but so far no useful results. I'm new at DAX, so probably I'm not using them right way..
Thanks in advance for any help!
Zuzana
Solved! Go to Solution.
Hi @Anonymous,
You can create calculated columns follow below DAX:
previous date of purchase = CALCULATE(MAX('Table1'[date of purchase]),FILTER(Table1,'Table1'[month of sale]=EARLIER(Table1[month of sale]) && 'Table1'[customer]=EARLIER(Table1[customer])&&'Table1'[product]=EARLIER(Table1[product])&&'Table1'[date of purchase]<EARLIER('Table1'[date of purchase])))
previous sales status = LOOKUPVALUE( Table1[sales status], Table1[month of sale], Table1[month of sale], Table1[customer], Table1[customer], Table1[product], Table1[product], Table1[date of purchase], Table1[previous date of purchase] )
Best Regards,
Qiuyun Yu
Hi @Anonymous,
You can create calculated columns follow below DAX:
previous date of purchase = CALCULATE(MAX('Table1'[date of purchase]),FILTER(Table1,'Table1'[month of sale]=EARLIER(Table1[month of sale]) && 'Table1'[customer]=EARLIER(Table1[customer])&&'Table1'[product]=EARLIER(Table1[product])&&'Table1'[date of purchase]<EARLIER('Table1'[date of purchase])))
previous sales status = LOOKUPVALUE( Table1[sales status], Table1[month of sale], Table1[month of sale], Table1[customer], Table1[customer], Table1[product], Table1[product], Table1[date of purchase], Table1[previous date of purchase] )
Best Regards,
Qiuyun Yu
https://community.powerbi.com/t5/Desktop/reference-Previous-row-using-measures/m-p/725894#M350298
help me out on the same issue.
Is there a way to do this with a measure instead of a column? My table has too many rows and there is not enough memory to solve it with a calculated column.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
100 | |
78 | |
64 | |
58 |
User | Count |
---|---|
148 | |
111 | |
94 | |
84 | |
67 |