cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

Post Patron

## Sum of sales from previous Monday until the date choosen

Hi,

I want to calculate sum of sales from Monday until now for weekly sales figures. How do I do that?

1 ACCEPTED SOLUTION
Community Support

Hi @bml123

You can try this measure

``````Total 3 =
VAR _selectDate = MAX ( 'Date'[Date] )
VAR _lastMonthEnd = EOMONTH ( _selectDate, -1 )
VAR _lastFridayDate =
IF (
WEEKDAY ( _lastMonthEnd, 2 ) >= 5,
_lastMonthEnd - WEEKDAY ( _lastMonthEnd, 2 ) + 5,
_lastMonthEnd - WEEKDAY ( _lastMonthEnd, 2 ) - 2
)
VAR _mondayDate = _lastFridayDate + 3
RETURN
CALCULATE (
SUM ( SalesTable[Sales] ),
ALL ( 'Date' ),
DATESBETWEEN ( 'Date'[Date], _mondayDate, _selectDate )
)
``````

Best regard,

Jing

If this post helps, please Accept it as Solution to help other members find it.

6 REPLIES 6
Community Support

Hi @bml123

Try this measure. When the selected date is Monday, it will only sum sales on that day.

``````Total from Monday =
VAR _selectDate = MAX ( 'Date'[Date] )
VAR _mondayDate = _selectDate - WEEKDAY ( _selectDate, 2 ) + 1
RETURN
CALCULATE (
SUM ( SalesTable[Sales] ),
ALL ( 'Date' ),
DATESBETWEEN ( 'Date'[Date], _mondayDate, _selectDate )
)
``````

Or if you want to sum sales from previous Monday to this Monday when the selected date is Monday, you can try below one

``````Total from Previous Monday =
VAR _selectDate = MAX ( 'Date'[Date] )
VAR _weekDay = WEEKDAY ( _selectDate, 2 )
VAR _mondayDate =
IF ( _weekDay = 1, _selectDate - 7, _selectDate - _weekDay + 1 )
RETURN
CALCULATE (
SUM ( SalesTable[Sales] ),
ALL ( 'Date' ),
DATESBETWEEN ( 'Date'[Date], _mondayDate, _selectDate )
)
``````

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Post Patron

Thank you for the solution.  It worked perfectly fine.

Now I want to get the sum of sales from monday that comes after last friday of the previous month.

For example, for 13 January 2022, monday that comes after last friday of the previous month is 03/01/2022.

I want to get sum of sales from 03/01/2022 until 13 January 2022 if I select 13 January 2022 in the slicer.

How do I achieve that?

Community Support

Hi @bml123

You can try this measure

``````Total 3 =
VAR _selectDate = MAX ( 'Date'[Date] )
VAR _lastMonthEnd = EOMONTH ( _selectDate, -1 )
VAR _lastFridayDate =
IF (
WEEKDAY ( _lastMonthEnd, 2 ) >= 5,
_lastMonthEnd - WEEKDAY ( _lastMonthEnd, 2 ) + 5,
_lastMonthEnd - WEEKDAY ( _lastMonthEnd, 2 ) - 2
)
VAR _mondayDate = _lastFridayDate + 3
RETURN
CALCULATE (
SUM ( SalesTable[Sales] ),
ALL ( 'Date' ),
DATESBETWEEN ( 'Date'[Date], _mondayDate, _selectDate )
)
``````

Best regard,

Jing

If this post helps, please Accept it as Solution to help other members find it.

Super User

Hi,

Create a Calendar Table with a relationhip from the Date column of the Data table to the Date column of the Calendar Table.  Create a slicer from the Date column of the Calendar Table and select a Date there.  Try this measure:

=calculate(sum(data[sales]),datesbetween(calendar[date],today()-weekday(min(calendar[date]),2)+1,min(calendar[date])))

Regards,
Ashish Mathur
http://www.ashishmathur.com
Post Patron

Sorry, your measure didn't work.  I have a slicer with all the dates from the calendar table and when I choose a date from the slicer, it should show me sum of sales from Monday until that day.  How do I achieve that?

Super User

@bml123 , You can use today or selected date

Week =
var _max1 = maxx(allselected('Date'), 'Date'[Date]) // or _max = today()
var _stweek = _max1 +-1*WEEKDAY(_max1,1)+1 //sunday week start
var _edweek= _max1+ 7-1*WEEKDAY(_max1,1)
return
calculate(sum(Table[Value]), filter(date, Date[Date] >=_stweek && Date[Date] <=_edweek))
// or use all date
//calculate(sum(Table[Value]), filter(all(date), Date[Date] >=_stweek && Date[Date] <=_edweek))

refer

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors