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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
DM_95
Helper I
Helper I

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
v-jianboli-msft
Community Support
Community Support

Hi @DM_95 ,

 

Based on your description I have created a simple sample:

vjianbolimsft_2-1668651650188.png

 

vjianbolimsft_1-1668651635024.png

Then create a slicer:

vjianbolimsft_3-1668653816233.png

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:

vjianbolimsft_4-1668653859437.png

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.

View solution in original post

1 REPLY 1
v-jianboli-msft
Community Support
Community Support

Hi @DM_95 ,

 

Based on your description I have created a simple sample:

vjianbolimsft_2-1668651650188.png

 

vjianbolimsft_1-1668651635024.png

Then create a slicer:

vjianbolimsft_3-1668653816233.png

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:

vjianbolimsft_4-1668653859437.png

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.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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