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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Joswin_100
Frequent Visitor

Have the last value of a movement table considering date and time

Good afternoon, I ask for your support I need to know the value of the inventory at the time a sales order is dispatched.

For this I have two tables: 1) Movements in inventory (which comes by product the entries that had it) 2) Ordenes_venta (contains the detail of the order and the items that make up that order)

The dax function I'm using is IF(HASONEVALUE(Ordenes_venta[ITEM_ID]),CALCULATE(MAX(Movements[VALUE_NEW]),FILTER(Movements,Movements[DATE_TIME]<-MAX(Movements[DATE_TIME]))))

With this formula, it brings me the maximum value of the filter context date but makes no distinction at the time of the sales order. (AS SHOWN IN THE PICTURE, TABLE ORDENES_VENTA)

What I need is to bring from the movement table, the last value (Value_New) whose DATE_TIME <- to DATE_TIME of the sales order

Captura.PNG

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

Hi, @Joswin_100 

 

It’s my pleasure to answer for you.

According to your description, I think you can create a measure to calculate the correct result.

Like this:

Measure =
VAR a =
    MAXX ( ALL ( 'order' ), [date-time] )
VAR b =
    MAXX ( FILTER ( ALL ( movements ), [date-time] <= a ), [date-time] )
RETURN
    SUMX ( FILTER ( ALL ( movements ), [date-time] = b ), [value new] )

v-janeyg-msft_0-1603699216158.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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-janeyg-msft
Community Support
Community Support

Hi, @Joswin_100 

 

It’s my pleasure to answer for you.

According to your description, I think you can create a measure to calculate the correct result.

Like this:

Measure =
VAR a =
    MAXX ( ALL ( 'order' ), [date-time] )
VAR b =
    MAXX ( FILTER ( ALL ( movements ), [date-time] <= a ), [date-time] )
RETURN
    SUMX ( FILTER ( ALL ( movements ), [date-time] = b ), [value new] )

v-janeyg-msft_0-1603699216158.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Joswin_100 , how these tables are connected ? Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

Hello

Thanks for your help.

In the image I show in red an example, as you will see transaction 120046171 has date of 11/08/2020 with a time of 11:15:44 pm and what I need is the VALUE_NEW field of the movements table whose date is less than or equal to that of the detail orders table. In my example I should bring the number 10 but it brings me the maximum value (17) for all transactions

Screenshot_1.png

My model is built like this

ACaptura.PNG

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.