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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

How to get MAX Date that is filtered by ID and snapshot calendar?

Hi,

I'm having issue with DAX calculated column.
I have fact Sales History table (daily snapshots of sales) - relationship to Calendar table: CalendarID - Planned Delivery Date ID. 

There is no direct relationship to Calendar Snapshot table (to see snapshots of data as of chosen date) - Calendar Table is used to filter data by Planned Delivery Date, so we can see how sales orders were progressing over time.

 

Now, Sales History table has multiple Planned Delivery Date entries on the same day for one ID (modifications). 

I want to calculate in a column MAX date for order ID that will be also filtered by Calendar Snapshot.

Max PRD =
VAR _table  =   CROSSJOIN ( DISTINCT ( 'Calendar - Snapshot'[Calendar Date] ), DISTINCT ( 'Sales History'[OrderID] ) )
VAR _result =  CALCULATE( MAX ( 'Sales History'[Planned Receipt Date] )
,  ALLEXCEPT (  'Sales History', 'Sales History'[OrderID] ) )

RETURN
_result


It cannot be a measure as I need it for further analyses.
 
 
OrderIDPlanned Receipt Date

Calendar Date
(snapshot date)

Max PRDWhat I'd like
123453/22/20243/1/20244/15/20243/22/2024
123453/22/20243/2/20244/15/20243/22/2024
123453/22/20243/3/20244/15/20243/22/2024
123453/22/20243/4/20244/15/20243/22/2024
123453/22/20243/5/20244/15/20244/2/2024
123454/2/20243/5/20244/15/20244/2/2024
123454/15/20243/6/20244/15/20244/15/2024
1 ACCEPTED SOLUTION
v-jialongy-msft
Community Support
Community Support

Hi @Anonymous 

 

Please try the following DAX:

Max = 
CALCULATE(
    MAX('Table'[Planned Receipt Date]), FILTER('Table',
    'Table'[OrderID] = EARLIER('Table'[OrderID])&&
    'Table'[Calendar Date]<= EARLIER('Table'[Calendar Date])
)
)

 

vjialongymsft_0-1714523623403.png

 

 

 

Best Regards,

Jayleny

 

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

Hi @Anonymous 

 

Please try the following DAX:

Max = 
CALCULATE(
    MAX('Table'[Planned Receipt Date]), FILTER('Table',
    'Table'[OrderID] = EARLIER('Table'[OrderID])&&
    'Table'[Calendar Date]<= EARLIER('Table'[Calendar Date])
)
)

 

vjialongymsft_0-1714523623403.png

 

 

 

Best Regards,

Jayleny

 

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

Wilson_
Super User
Super User

DoraRS,

 

If I am following your data and question correctly, you want the calculated column to be dynamically calculated, based on slicer selections? If so, this is impossible because calculated columns are calculated at model refresh time.

 

Not sure why you need it as a calculated column, but unless you're wanting to use these values in your visual's row or column, I'm not convinced it couldn't be a measure.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)


P.S. Need a more in-depth consultation for your Power BI issue? Feel free to hire me on Upwork or to DM me on here to discuss how we can make your problems disappear. 😄




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Anonymous
Not applicable

Hmm...

I need to calculate sales order values that have been pushed to another month - and to be able to see when it happened (calendar snapshot)

so, case scenario:

 

We have total sales orders value of 50.000 with planned receipt date for April - and this is what we see as of March 5th. 

 

As of March 6th we have 40.000 - because 10.000 were moved to May.

 

So - my idea was to calculate Planned Receipt Date for Calendar Snapshot Date March 5th and compare it with Planned Receipt Date for Calendar Snapshot Date March 6th. 

 

If Planned Receipt Date March 5th < Planned Receipt Date March 6 then it means this order has been postponed.

 

I created a measure... but I need to visualize it on Total Sales Order Value per each Calendar Snapshot Date - and this takes MAX Planned Receipt Date of all Order IDs as they are aggregated, and this still needs to be treated on a row level... The only idea I had was to have a calculated column which would correspond to specific OrderID visible on certain Calendar Snapshot Date.

 

Not sure if I explained it correctly...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.