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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
user555
New Member

Find value from column X corresponding the max value in column y

I have a small problem that I cant solve in efficient way. I want to create a new column "lastDatesales" which has "sum of sales "corresponding to the last purchase dates sales a company has. For example, company "a":s last purchase date was 10.1.2019, so I want to get the corresponding sales from that date to each row the company has.

My current solution is: 

lastDatesales = maxx(filter(Sheet1;Sheet1[company]=earlier(Sheet1[company]));if(Sheet1[date]=maxx(filter(Sheet1;Sheet1[company]=earlier(Sheet1[company]));Sheet1[date]);Sheet1[sales];0))

 

datesalescompanylastDatesales (correct answer)
1.1.2019100a200
10.1.2019200a200
1.1.2018300b600
15.1.2018600b600
1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @user555 

Modify az38's solution as below, then it can use to create a column

 

lastDatesales = 
var _lastDate = calculate(MAX(Sheet1[date]),ALLEXCEPT(Sheet1,Sheet1[company]))
return
LOOKUPVALUE(Sheet1[sales],Sheet1[company],Sheet1[company],Sheet1[date],_lastDate)

 

Capture4.JPG

Measure may perform quicker than column.

Check the performance under View->Performance Analyzer.

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @user555 

Modify az38's solution as below, then it can use to create a column

 

lastDatesales = 
var _lastDate = calculate(MAX(Sheet1[date]),ALLEXCEPT(Sheet1,Sheet1[company]))
return
LOOKUPVALUE(Sheet1[sales],Sheet1[company],Sheet1[company],Sheet1[date],_lastDate)

 

Capture4.JPG

Measure may perform quicker than column.

Check the performance under View->Performance Analyzer.

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks a lot az38 and Maggie! Both answers were really helpful.

 

az38
Community Champion
Community Champion

hi @user555 

try a measure

lastDatesales = 
var _lastDate = calculate(MAX(Sheet1[date]);ALLEXCEPT(Sheet1;Sheet1[company]))
return
LOOKUPVALUE(Sheet1[sales];Sheet1[company];SELECTEDVALUE(Sheet1[company]);Sheet1[date];_lastDate)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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