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

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.

Reply
azaterol
Helper V
Helper V

Special situation with date

Hello everyone,

I'm really frustrated and I hope you can help me.
I have two tables that only match the article number. Both tables have a date. If the date from the log table is greater than or equal to the date from the item table, the price should appear in the column and apply from then until a new price is set.

 

You have an idea for a measure ?

 

azaterol_1-1662118670093.png

 

 

Example:

Initial situation

Item table:

Item Date
A 01/30/2020
A 01/31/2020
A

 

02/02/2020

A

 

02/23/2020

A

 

02/25/2020

 

Log table:

Item Log date Sell price Buy price
A 01/30/2020 $5,00 $2,00
A 02/03/2020 $4,00 $3,00

 

Expected sitation:

Item table:

Item Date Sell price Buy price
A  01/30/2020 $5,00 $2,00
A  01/31/2020 $5,00 $2,00
A 02/02/2020 $5,00 $2,00
A 02/23/2020 $4,00 $3,00
A 02/25/2020 $4,00 $3,00
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @azaterol ;

Try this measure:

Sell price = 
var _maxdate=CALCULATE(MAX('Log'[Log date]),FILTER('Log',[Log date]<=MAX('Item'[Date])))
return CALCULATE(MAX('Log'[Sell price]),FILTER('Log',[Log date]=_maxdate))
Buy price = 
var _maxdate=CALCULATE(MAX('Log'[Log date]),FILTER('Log',[Log date]<=MAX('Item'[Date])))
return CALCULATE(MAX('Log'[Buy price]),FILTER('Log',[Log date]=_maxdate))

The final show:

vyalanwumsft_0-1662450614979.png


Best Regards,
Community Support Team _ Yalan Wu
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

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @azaterol ;

Try this measure:

Sell price = 
var _maxdate=CALCULATE(MAX('Log'[Log date]),FILTER('Log',[Log date]<=MAX('Item'[Date])))
return CALCULATE(MAX('Log'[Sell price]),FILTER('Log',[Log date]=_maxdate))
Buy price = 
var _maxdate=CALCULATE(MAX('Log'[Log date]),FILTER('Log',[Log date]<=MAX('Item'[Date])))
return CALCULATE(MAX('Log'[Buy price]),FILTER('Log',[Log date]=_maxdate))

The final show:

vyalanwumsft_0-1662450614979.png


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

Anonymous
Not applicable

Hi  @ Azaterol,

 

Please find the code for your 2 requested columns

Sell_Price =
var selitem='Item'[Item]
var datemax='Item'[Date]
var calcdate=calculate(max('Log'[Log date]),'Log'[Item]=selitem&&'Log'[Log date]<=datemax)
var result=calculate(max('Log'[Sell price]),'Log'[Item]=selitem&&'Log'[Log date]=calcdate)
return
result
 
Sell_Price =
var selitem='Item'[Item]
var datemax='Item'[Date]
var calcdate=calculate(max('Log'[Log date]),'Log'[Item]=selitem&&'Log'[Log date]<=datemax)
var result=calculate(max('Log'[Sell price]),'Log'[Item]=selitem&&'Log'[Log date]=calcdate)
return
result
JamesFr06_0-1662122773920.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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