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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jrscaletta
Helper II
Helper II

Obtain value between 2 dates

Hi all!

 

I have 2 tables:

 

1) SALES TABLE

Customer IDProduct IDDate  Amount €
1 55 03/01/2020 500 €
2 66 01/02/2020 600 €
3 55 01/02/2020 700 €

 

2) COST TABLE

Product IDSince Date To Date Cost €
5501/01/2020 31/01/2020  25 €
5501/02/2020 29/02/2020  30 €
6601/01/2020 31/07/2020  99 €

 

Then, I want to obtain COST € for every row of first table.

 

I am not using date tables.My date filter is "DATE" of table "SALES TABLE". Thanks in advance.

 

Thanks in advance.

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@jrscaletta , new column in sales table

new column: maxx(filter(cost, cost[Product ID] ?sales[Product ID] && Sales[Date]>'cost[From Date] && Sales[Date]<'cost[Date to]),Cost[Cost'])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

v-kelly-msft
Community Support
Community Support

Hi  @jrscaletta,

 

Create a column as below:

Column = 
var _cost=CALCULATE(MIN('COST TABLE'[ Cost €]),FILTER(ALL('COST TABLE'),'COST TABLE'[Product ID]='SALES TABLE'[Product ID]&&'COST TABLE'[Since Date]<=EARLIER('SALES TABLE'[Date])&&'COST TABLE'[ To Date]>=EARLIER('SALES TABLE'[Date])))
Return
_cost

And you will see:

Annotation 2020-07-31 172211.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi  @jrscaletta,

 

Create a column as below:

Column = 
var _cost=CALCULATE(MIN('COST TABLE'[ Cost €]),FILTER(ALL('COST TABLE'),'COST TABLE'[Product ID]='SALES TABLE'[Product ID]&&'COST TABLE'[Since Date]<=EARLIER('SALES TABLE'[Date])&&'COST TABLE'[ To Date]>=EARLIER('SALES TABLE'[Date])))
Return
_cost

And you will see:

Annotation 2020-07-31 172211.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
amitchandak
Super User
Super User

@jrscaletta , new column in sales table

new column: maxx(filter(cost, cost[Product ID] ?sales[Product ID] && Sales[Date]>'cost[From Date] && Sales[Date]<'cost[Date to]),Cost[Cost'])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors