Forum Discussion

Nellis5's avatar
Nellis5
Regular Visitor
1 year ago
Solved

How to return the previous date using a parameter selected range

I'm having trouble creating a measure to display previous dates from an order date column based on a parameter. I tried to make it a calculated column until I learned that parameters don't update in those columns. Ultimately, I'd like to be able to compare the previous date against the current order date in a row and calculate the difference (again inside a measure).

 

Using Window functions and offsets have gotten me close, but I keep ending up with a blank column. Alternatively, some of the measures I've tried produce values, but don't give me the previous (see measure below)

 

Previous = MINX(WINDOW(-[Number of Orders Value],REL,0,REL,OrderTable,ORDERBY([Order Date],ASC),,PARTITIONBY([Customer]),MATCHBY([Order Number])),OrderTable[Order Date])

 

 

Desired

 

When the parameter([Number of Orders Value]) is set to 2

 

CustomerOrder NumberOrderDatePrevious
1Foo19/10/20249/10/2024
1Foo29/12/20249/10/2024
1Foo39/13/20249/12/2024
1Foo49/19/20249/13/2024
2Bar19/12/20249/12/2024
2Bar29/15/20249/12/2024
2Bar39/19/20249/15/2024
2Bar49/20/20249/19/2024
  • Sometimes it just takes asking to find the answer. I was very close with the DAX I posted, I just had to add "ALLSELECTED" to the relation to make it work.

     

    Final DAX, Change in bold
    Previous = MINX(WINDOW(-[Number of Orders Value],REL,0,REL,ALLSELECTED(OrderTable),ORDERBY([Order Date],ASC),,PARTITIONBY([Customer]),MATCHBY([Order Number])),OrderTable[Order Date])

1 Reply

  • Nellis5's avatar
    Nellis5
    Regular Visitor

    Sometimes it just takes asking to find the answer. I was very close with the DAX I posted, I just had to add "ALLSELECTED" to the relation to make it work.

     

    Final DAX, Change in bold
    Previous = MINX(WINDOW(-[Number of Orders Value],REL,0,REL,ALLSELECTED(OrderTable),ORDERBY([Order Date],ASC),,PARTITIONBY([Customer]),MATCHBY([Order Number])),OrderTable[Order Date])