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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.

amitchandak
Super User
Super User

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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