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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
matteomatilde
Frequent Visitor

How to get the value corresponding to the earliest date of a table in DAX?

Hello to everyone!

This is my table:

STK_IDSTK_ITM_IDSTK_QTYSTK_DATE
1I0001301 Jan 21
2I0002403 Jan 21
3I0003501 Jan 21
4I0001344 Jan 21
5I0002354 Jan 21

 

The result I would like to have is:

STK_ITM_IDSTK_QTY
I000130
I000240
I000350

 

How can I get the STK_QTY values, for each item, corresponding to the earliest dates?

 

Thank you in advance.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @matteomatilde 

Please check the below picture and the sample pbix file's link down below.

 

Picture1.png

 

qty total = SUM('Table'[STK_QTY])
 
STK QTY Earliest =
VAR groupbyitem =
GROUPBY (
'Table',
'Table'[STK_ITM_ID],
"earliest", MINX ( CURRENTGROUP (), 'Table'[STK_DATE] )
)
RETURN
CALCULATE (
[qty total],
FILTER ( 'Table', 'Table'[STK_DATE] = MINX ( groupbyitem, [earliest] ) )
)
 
STK QTY Earliest Total fix =
SUMX(VALUES('Table'[STK_ITM_ID]), [STK QTY Earliest])
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi, @matteomatilde 

Please check the below picture and the sample pbix file's link down below.

 

Picture1.png

 

qty total = SUM('Table'[STK_QTY])
 
STK QTY Earliest =
VAR groupbyitem =
GROUPBY (
'Table',
'Table'[STK_ITM_ID],
"earliest", MINX ( CURRENTGROUP (), 'Table'[STK_DATE] )
)
RETURN
CALCULATE (
[qty total],
FILTER ( 'Table', 'Table'[STK_DATE] = MINX ( groupbyitem, [earliest] ) )
)
 
STK QTY Earliest Total fix =
SUMX(VALUES('Table'[STK_ITM_ID]), [STK QTY Earliest])
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

I'm sorry, but I've got another problem. The measures you gave me totally work when they are applied to the FACT_STK, but I can't make them work with the FACT_MOV, since I get the same date and quantities for all rows.

 

Can you help me?

https://www.dropbox.com/s/ksvc1jme2lb4jql/matteo.pbix?dl=0

 

Thank you so much!

Hi, @matteomatilde 

Thank you for your feedback.

Sorry that I cannot know how your desired outcome looks like.

Please correct me if I am wrong, but STK ids are not filtering MOV table, right?


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Oh yes, you are perfectly right, @Jihwan_Kim , sorry! By using the item ID from the MSTR_ITM it works fine.

However, I'm making these measures with the purpose of calculating the average stock of the four warehouses, as I explained in my latest question here in the forum, but I don't know if I am taking the right approach. If you have time, can you please check that post? Thank you so much and sorry, again! 

Thank you!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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