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.
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)
Solved! Go to Solution.
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))
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.
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
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))
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.
@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])))
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
99 | |
73 | |
72 | |
49 |
User | Count |
---|---|
145 | |
109 | |
108 | |
90 | |
64 |