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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
lpost1214
Regular Visitor

Help with Formula to return a value for the max date for each unique ID

I have historical forecast data for all forecated materials and below is an example of one. I would like to create a formula to return the 'planned qty' for the latest 'date of last change' for each 'key'.  

 

lpost1214_0-1667241475571.png

Once i have this value i am looking to put in a matrix format. i.e. below 202209 it should show 484, 202210 should show 500, etc. 

lpost1214_1-1667241555228.png

Thanks in advance! 

 

2 ACCEPTED SOLUTIONS
lukiz84
Memorable Member
Memorable Member

Ah ok, yeah, measure makes sense, should work:

 

 

PlannedQty =
   CALCULATE(
      MAX(Forecast[Planned quantity_PLNMG]),
      FILTER(
         Forecast,
         Forecast[Date of Last Change_LAEDA] = MAX(Forecast[Date of Last Change_LAEDA])
      )
   )

 

 

 

View solution in original post

Hi, @lpost1214 

 

You can try the following methods.

Column:

Column =
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( 'Table', [Key] = EARLIER ( 'Table'[Key] ) )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Planned] ),
        FILTER ( 'Table', [Key] = EARLIER ( 'Table'[Key] ) && [Date] = _maxdate )
    )

vzhangti_0-1667369132858.png

Result:

vzhangti_1-1667369165304.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

6 REPLIES 6
lukiz84
Memorable Member
Memorable Member

Ah ok, yeah, measure makes sense, should work:

 

 

PlannedQty =
   CALCULATE(
      MAX(Forecast[Planned quantity_PLNMG]),
      FILTER(
         Forecast,
         Forecast[Date of Last Change_LAEDA] = MAX(Forecast[Date of Last Change_LAEDA])
      )
   )

 

 

 

One more question. I am trying to put this into a matrix where i can view the results by customer, product group, or all of the individual material results from the calculation you have provided.  Currently, if i use the planned qty formula you provided and i collapse from material up one level to customer/brand, i don't get a sum of each of the calculated planned qtys. In the example below, i'd expect the result for 01-Jul to be 1,425, not 150. How can i achieve that? 

lpost1214_0-1667401758593.png

 

Thank you, this worked. How would i calculate it as a column? I have a similar scenario that i think may work better by adding a column.

Hi, @lpost1214 

 

You can try the following methods.

Column:

Column =
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( 'Table', [Key] = EARLIER ( 'Table'[Key] ) )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Planned] ),
        FILTER ( 'Table', [Key] = EARLIER ( 'Table'[Key] ) && [Date] = _maxdate )
    )

vzhangti_0-1667369132858.png

Result:

vzhangti_1-1667369165304.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

lpost1214
Regular Visitor

I think i'd like to have it calculated as a measure, but i honestly get confused about when is the correct instance to use each. Thank you!

lukiz84
Memorable Member
Memorable Member

Hi,

 

do you want it as a calculated column or a measure?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.