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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ghosh_kavitha
Helper IV
Helper IV

How to calculate sum of this monday to sunday value - Measure

 
Hi
 How to calculate sum of this week's monday to sunday values & the following week's sum of monday to saunday values.
  ex
this week monday 23/03/2020 to sunday 29/03/2020
following week 30/03/2020 to sunday 05/03/2020  
Thanks in anticipation
Kavitha ghosh
1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@ghosh_kavitha 

There is a problem with the week number method. For the last week of this year is 2020,12,28 - 2021,1,3, the week numbers are different(53 and 1) although they are in the same week. To prevent this problem, I would recommend you to use monday as the flag.

 

In this way, this week would be dates between thismonday and this sunday(monday+6), and next week would be next monday, next sunday(next monday+6).

 

Measure = 
var thismonday=MAXX(FILTER('Table',[Date]<=TODAY()&&WEEKDAY('Table'[Date],2)=1),'Table'[Date])
var nextmonday=MINX(FILTER('Table',[Date]>=TODAY()&&WEEKDAY('Table'[Date],2)=1),'Table'[Date])
Return CALCULATE(SUM('Table'[Value]),DATESBETWEEN('Table'[Date],thismonday,thismonday+6))

 

 

Paul Zheng
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

3 REPLIES 3
V-pazhen-msft
Community Support
Community Support

@ghosh_kavitha 

There is a problem with the week number method. For the last week of this year is 2020,12,28 - 2021,1,3, the week numbers are different(53 and 1) although they are in the same week. To prevent this problem, I would recommend you to use monday as the flag.

 

In this way, this week would be dates between thismonday and this sunday(monday+6), and next week would be next monday, next sunday(next monday+6).

 

Measure = 
var thismonday=MAXX(FILTER('Table',[Date]<=TODAY()&&WEEKDAY('Table'[Date],2)=1),'Table'[Date])
var nextmonday=MINX(FILTER('Table',[Date]>=TODAY()&&WEEKDAY('Table'[Date],2)=1),'Table'[Date])
Return CALCULATE(SUM('Table'[Value]),DATESBETWEEN('Table'[Date],thismonday,thismonday+6))

 

 

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

RMB
Resolver II
Resolver II

The Weekday and Weeknum functions should be capable of doing this for you.

A quick example below, you would want to add a year check.

WeekTotals =
VAR __ThisWeek = WEEKNUM(TODAY(), 2)
VAR __NextWeek = __ThisWeek + 1

RETURN
CALCULATE(SUM('Table1'[ColumnToSum]), FILTER('Table1', WEEKNUM(T1[Date],2) = __ThisWeek))

 

amitchandak
Super User
Super User

@ghosh_kavitha , You can create a date calendar and week start and week end based on that. You can create a week name based on that. Refer, how to so in the calendar and how to use it

 

https://www.dropbox.com/s/a9xq913pgvuzg2x/sales_analytics_weekWiseMon_sun.pbix?dl=0

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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