Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi experts!
I have a sales table and an order table.
Simple tables that contains article, date and value. Both tables are linked to a calendar table.
Sales
Article | Date | Value |
A | 01.10.2022 | 500 |
Order
Article | Date | Value | Shared Date (Year-Week) |
A | 01.11.2022 | 500 | 2022-39 |
A | 15.01.2022 | 600 | 2022-40 |
There is a slicer on the report page with "Shared Date". Now I would like to sum up the sales for the selected time horizon (Shared Date) including the next 4 weeks.
If I select 2022-39, then I would like to get the sales for 2022-39, 2022-40, 2022-41, 2022-42, 2022-43.
How would you do that in DAX?
Solved! Go to Solution.
please try these steps
1, add a column in the calendar table, Year-Week
2, create a measure
=VAR _yw=selectedvalue(orders[Shared Date(Year_Week)])
VAR _selectedweeks=topn(4,filter(allselected(calendar[year-week]),calendar[year-week]>=_yw),calendar[year-week],ASC)
return
calculate(sum(Sales[Value]),treatas(_selectedweeks,calendar[year-week]))
try these steps
1, add a new dimension table, say YearWeek, as the slicer table with no relationships.
YearWeek=Values(orders[Shared Date(Year_Week)])
2, put the calendar[Year-Week] on the visual, and amend the meausre
=VAR _yw=selectedvalue(YearWeek[Shared Date(Year_Week)])
VAR _selectedweeks=topn(4,filter(allselected(calendar[year-week]),calendar[year-week]>=_yw),calendar[year-week],ASC)
return
if(max(calendar[year-week]) IN _selectedweeks,sum(Sales[Value]))
please try these steps
1, add a column in the calendar table, Year-Week
2, create a measure
=VAR _yw=selectedvalue(orders[Shared Date(Year_Week)])
VAR _selectedweeks=topn(4,filter(allselected(calendar[year-week]),calendar[year-week]>=_yw),calendar[year-week],ASC)
return
calculate(sum(Sales[Value]),treatas(_selectedweeks,calendar[year-week]))
@wdx223_Daniel : That works perfectly fine! Thanks.
Is it possible to display/ split this result for the weekly aggregation? Maybe using a second calendar table?
I would like to see the sum per week.
If I use a second calendar table, then I get the correct values per week. But every other week is also displayed but with a 0
try these steps
1, add a new dimension table, say YearWeek, as the slicer table with no relationships.
YearWeek=Values(orders[Shared Date(Year_Week)])
2, put the calendar[Year-Week] on the visual, and amend the meausre
=VAR _yw=selectedvalue(YearWeek[Shared Date(Year_Week)])
VAR _selectedweeks=topn(4,filter(allselected(calendar[year-week]),calendar[year-week]>=_yw),calendar[year-week],ASC)
return
if(max(calendar[year-week]) IN _selectedweeks,sum(Sales[Value]))
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |