cancel
Showing results for
Did you mean:
Helper II

Sum of 2nd latest value from non-continuous selection

I have a slicer that allows users to select a week ending date(s).

The selection the user makes will not always be continuous e.g. may select w/e 31st January, 17th January, 10th January

I want to sum Total Sales for the 2nd-latest week selected, how would I do that in DAX? (so for the 17th January in the above example)

1 ACCEPTED SOLUTION
Community Support

In order to get the total value of the next week of the selected date, you need to create a separate date table. In Filters, set Show items when the value is 7. This is to keep the last date of the week in the slicer.

``DateTable = ADDCOLUMNS(CALENDAR(DATE(2021,1,1),DATE(2021,12,31)),"WEEKDAY",WEEKDAY([Date],2))``

Create the measure.

``````Total value =
CALCULATE (
SUM ( 'MainTable'[Value] ),
FILTER (
'MainTable',
WEEKNUM ( [Date], 2 )
= WEEKNUM ( SELECTEDVALUE ( DateTable[Date] ), 2 ) + 1
)
)``````

You can check more details from here.

Tips: Since I used the RANDBETWEEN function, the value in the main table may change randomly. Please pay attention to the result after the change.😋

Best Regards,

Stephen Tao

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

3 REPLIES 3
Community Support

Could you tell me if your problem has been solved?
If it is, kindly Accept it as the solution. More people will benefit from it.

Best Regards,
Stephen Tao

Community Support

In order to get the total value of the next week of the selected date, you need to create a separate date table. In Filters, set Show items when the value is 7. This is to keep the last date of the week in the slicer.

``DateTable = ADDCOLUMNS(CALENDAR(DATE(2021,1,1),DATE(2021,12,31)),"WEEKDAY",WEEKDAY([Date],2))``

Create the measure.

``````Total value =
CALCULATE (
SUM ( 'MainTable'[Value] ),
FILTER (
'MainTable',
WEEKNUM ( [Date], 2 )
= WEEKNUM ( SELECTEDVALUE ( DateTable[Date] ), 2 ) + 1
)
)``````

You can check more details from here.

Tips: Since I used the RANDBETWEEN function, the value in the main table may change randomly. Please pay attention to the result after the change.😋

Best Regards,

Stephen Tao

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

Super User IV

Second last =
var _max= maxx(allselected(Date), Date[week end Date])
return
calculate(max(Date[week end Date]), filter(allselected(Date), Date[week end Date]<_max))

or a measure like this with modification of date

Last Day Non Continuous = CALCULATE([sales],filter(ALLSELECTED('Date'),'Date'[Date] =MAXX(FILTER(ALLSELECTED('Date'),'Date'[Date]<max('Date'[Date])),'Date'[Date])))

Proud to be a Super User!

Announcements