cancel
Showing results for
Did you mean:

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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 Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

#### Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

#### The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors