cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thisisausername
Helper II
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
v-stephen-msft
Community Support
Community Support

Hi @thisisausername ,

 

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))

5.png 

Create the measure.

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

6.png

7.png

 

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.

View solution in original post

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @thisisausername ,

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.
Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.


Best Regards,
Stephen Tao

v-stephen-msft
Community Support
Community Support

Hi @thisisausername ,

 

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))

5.png 

Create the measure.

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

6.png

7.png

 

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.

View solution in original post

amitchandak
Super User IV
Super User IV

@thisisausername , Please try for date , a measure

 

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])))



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Top Solution Authors
Top Kudoed Authors