cancel
Showing results for
Did you mean:
Frequent Visitor

## Measure to calculate previous week of selected week. No selection=previous week of current week

Hi All,

I need some help regarding a measure to calculate the net sales of previous week when a week in slicer 'Week' is selected e.g. when Week 46 is selected in the slicer, I want the net sales of Week 45 (It also needs to take into account when Week 1 is selected, I would need the net sales of Week 52 of previous year). When there is no selection in slicer 'Week', it needs to show the net sales of previous week of the current week. When multiple weeks are selected in the slicer, it needs to show the previous week of the earliest week. For example when weeks 3 and 4 are selected, it needs to show the net sales of week 2.

I have created this measure for previous month of the selected month, but I can't seem to figure it out for previous week. Any help is welcome 🙂

VAR _max1 = IF(ISFILTERED('Invoice Date'[MonthInYear]), MAX('Invoice Date'[DateFull]), TODAY())
VAR _max = EOMONTH(_max1,-1)
VAR _min = EOMONTH(_max1,-2) +1
VAR _1month = CALCULATE([Net Sales], DATESBETWEEN('Invoice Date'[DateFull],_min,_max))
VAR _max3 = IF(ISFILTERED('Invoice Date'[MonthInYear]), MIN('Invoice Date'[DateFull]), TODAY())
VAR _max2 = EOMONTH(_max3,-1)
VAR _min2 = EOMONTH(_max3,-2) +1
VAR _xmonths = CALCULATE([Net Sales], DATESBETWEEN('Invoice Date'[DateFull],_min2,_max2))
RETURN
IF(COUNTROWS(ALLSELECTED('Invoice Date'[MonthInYear]))=1, _1month, _xmonths)
1 ACCEPTED SOLUTION
Community Support

Hi @DM_95 ,

Based on your description I have created a simple sample:

Then create a slicer:

Apply the measure:

``````Measure =
var _a = SELECTCOLUMNS('Date',"Week",[Week])
var _b = MINX(_a,[Week])-1
return CALCULATE(SUM(Sales[Net Sales]),FILTER(ALL('Date'),[Week]=_b))``````

Final output:

Best Regards,

Jianbo Li

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

Community Support

Hi @DM_95 ,

Based on your description I have created a simple sample:

Then create a slicer:

Apply the measure:

``````Measure =
var _a = SELECTCOLUMNS('Date',"Week",[Week])
var _b = MINX(_a,[Week])-1
return CALCULATE(SUM(Sales[Net Sales]),FILTER(ALL('Date'),[Week]=_b))``````

Final output:

Best Regards,

Jianbo Li

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

Announcements

#### Power BI T-Shirt Design Challenge 2023

Vote for your favorite t-shirt design now through March 28.

#### Power BI March 2023 Update

Find out more about the March 2023 update.

#### March 2023 Events

Find out more about the online and in person events happening in March!

Top Solution Authors
Top Kudoed Authors