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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jay_patel
Helper IV
Helper IV

Want Sum of sales in while getting from another table using lookup but only for maximum date.

Hello All ,

I am trying to get values from Table B to Table A using lookup functions using 'KEY'. Please have a look on both tables.

 table A
  
datekey
01-02-2021AA
02-02-2021AA
03-02-2021AA
04-02-2021BB
05-02-2021CC
06-02-2021DD
07-02-2021DD
08-02-2021EE
09-02-2021FF
10-02-2021FF

 

 

table B 
  
keyValue
AA100
BB200
CC200
DD300
EE150
FF100

 

and I am trying to get values from table B to A. right now this is what i am getting,

 Current_Result 
   
datekeyLookupValue
01-02-2021AA100
02-02-2021AA100
03-02-2021AA100
04-02-2021BB200
05-02-2021CC200
06-02-2021DD300
07-02-2021DD300
08-02-2021EE150
09-02-2021FF100
10-02-2021FF100

 

here it's getting for every row item for matching key but i only want for maximum date only. 


 

 Expected_Result
   
datekeyLookupValue
01-02-2021AA 
02-02-2021AA 
03-02-2021AA100
04-02-2021BB200
05-02-2021CC200
06-02-2021DD 
07-02-2021DD300
08-02-2021EE150
09-02-2021FF 
10-02-2021FF100

 

Thanks in Advance

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @jay_patel ,

 

Please check this formula.

Column = 
var _max = CALCULATE(MAX('Table A'[date]),FILTER('Table A','Table A'[key]=EARLIER('Table A'[key])))
var _value = CALCULATE(SUM('Table B'[Value]),FILTER('Table B','Table B'[key]='Table A'[key]))
return
IF('Table A'[date]=_max,_value,BLANK())

vjaywmsft_0-1649851863424.png

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

6 REPLIES 6
v-jayw-msft
Community Support
Community Support

Hi @jay_patel ,

 

Please check this formula.

Column = 
var _max = CALCULATE(MAX('Table A'[date]),FILTER('Table A','Table A'[key]=EARLIER('Table A'[key])))
var _value = CALCULATE(SUM('Table B'[Value]),FILTER('Table B','Table B'[key]='Table A'[key]))
return
IF('Table A'[date]=_max,_value,BLANK())

vjaywmsft_0-1649851863424.png

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Tahreem24
Super User
Super User

@jay_patel Try this DAX measure:

Measure =
VAR a_ = CALCULATE(MAX(Table1[date]),ALLEXCEPT(Table1,Table1[key]))
RETURN CALCULATE(SUM(Table2[Value]),FILTER(Table1,Table1[date]=a_))
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Screenshot (422).png

 

It's not taking Column of Value.

Shishir22
Solution Sage
Solution Sage

Hello @jay_patel ,

 

Please use below DAX as calculated column -

 

LookupValue = 
Var A = Calculate(MAX('Table A'[date]),ALLEXCEPT('Table A','Table A'[key]))
Return
if('Table A'[date]=A,RELATED('Table B'[Value]),BLANK())

 

Shishir22_0-1649415861974.png

 

Please Accept it as solution if it solves your issue. Kudos are also appreciated.

 

Cheers,

Shishir

 

Cheers,
Shishir

Screenshot (422).png

Give relationship between tableA and TableB on key column.

 

Cheers,

Shishir

Cheers,
Shishir

Helpful resources

Announcements
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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.