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
Anonymous
Not applicable

Calculated Column to return latest value of another column by unique product, for each month

Hello Community, 

 

I would like to accomplish the same solution achieved in this article, but to modify the latest date constraint to apply for *each month*.

 

https://stackoverflow.com/questions/55474913/how-to-get-the-latest-values-of-a-column-per-each-disti...

 

Below is what I would like to achieve - End of Month Value is the desired column.

 

Thanks in advance for your input!

 

klp97_0-1654031904580.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you so much! 

 

I actually figured out how to do it using ALLEXCEPT as follows:

1. Created column YearMonth =

YearMonth = CONCATENATE(YEAR([Stock Date]),MONTH([Stock Date]))
 
2. Calucated Column Formula:
 
End of month Value =
VAR Latest_Date_In_Month =
CALCULATE(MAX([Stock Date]),ALLEXCEPT([YearMonth],[SKU]))
RETURN
IF([Del/finish]=Latest_Date_In_Month, [Stock Value],0)
 
It seems like it produces the desired result - do you see any reason why it wouldn't?
 
 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Apologies! My sample table was wrong - here is the correct table showing desired results:

 

klp97_0-1654032917548.png

 

Hi:

Please have Date Table connected to this your Fact Table. Mark as Date Table. Form relationship with your Fact Table (Date to Stock Date).

First Measure:

Stock Value = SUM(Table[Stock Value])

 

Last Value = CALCULATE( LASTNONBLANKVALUE(DISTINCT(Dates[Date]), [Stock Value]))

or

Last Value = CALCULATE([Stock Value]), LASTNONBLANK(Dates[Date], [Stock Value]))

 

If you want calculated column:

Lst Stock Month Price =
VAR currentMonth =
MONTH( Data[Stock Date])
VAR currentYear =
YEAR( Data[Stock Date] )
VAR latestpriceMonth =
CALCULATE (
LASTNONBLANKVALUE(Dates[Date],MAX(Data[Stock Value])),
FILTER ( ALL(Data), MONTH( Data[Stock Date]) = currentMonth && YEAR( Data[Stock Date]) = currentYear), ALLEXCEPT(Data, Data[SKU]))
return
latestpriceMonth
 
Whitewater100_0-1654045954529.png

I hope this helps!

Anonymous
Not applicable

Thank you so much! 

 

I actually figured out how to do it using ALLEXCEPT as follows:

1. Created column YearMonth =

YearMonth = CONCATENATE(YEAR([Stock Date]),MONTH([Stock Date]))
 
2. Calucated Column Formula:
 
End of month Value =
VAR Latest_Date_In_Month =
CALCULATE(MAX([Stock Date]),ALLEXCEPT([YearMonth],[SKU]))
RETURN
IF([Del/finish]=Latest_Date_In_Month, [Stock Value],0)
 
It seems like it produces the desired result - do you see any reason why it wouldn't?
 
 

Awesome. The measures look good. Please mark as solution or kudos if you can.  Thanks!

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.