cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sguenther
Advocate II
Advocate II

Sum over current week

Hi everybody,

 

I want to create a simple measure but just can't figure out how to write it properly. Here we go:

 

Let#s say I have a table with two columns:

 

Date    |    Logged in

1.1.2018   |    2

2.1.2018    |    5

3.1.2018    |    6

...

 

So basically a list with people who have been logged into my app on which days.

 

Now I want to create a line chart that shows me the sum of all logins always for the current week. But only for the current week, not counting in any logins from before the start of the week.

 

y axis: # Logins

x axis: Mon, Tue, Wed, Thu, Fri, Sat, Sun (from a separate date table)

 

That means the line chart is always going up.

 

The problem which I can't overcome is, that I don't know how to retrieve the start of the week date for every day of the week. I tried something like this, but it doesn't work:

 

# Logins for current week = 
CALCULATE(
	COUNTROWS('Logins'),
	FILTER('Logins',
		'Calendar'[Date] <= MAX('Calendar'[Date]) &&
        'Calendar'[Date] >= MIN(ALL('Calendar'[Date]))
	)  
) + 0

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

To replicate your problem I have created a table with a date field and a loggedin field that is populated with numbers.

The following measures will give you the sum of the logged in values only for the week of the date set in the _Today Variable. If you want this to be the current date then set the variable to be equal to UTCTODAY()

 

Current Week = 
VAR _Today =
    DATE ( 2018, 1, 8 )
VAR _StartOfWeek =
    _Today - WEEKDAY ( _Today, 2 ) + 1
VAR _EndOfWeek =
    _Today
        + ( 7 - WEEKDAY ( _Today, 2 ) )
RETURN
    IF (
        MAX ( Table1[date] ) >= _StartOfWeek
            && MAX ( Table1[date] ) <= _EndOfWeek,
        SUM ( Table1[loggedin] ),
        BLANK ()
    )

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

To replicate your problem I have created a table with a date field and a loggedin field that is populated with numbers.

The following measures will give you the sum of the logged in values only for the week of the date set in the _Today Variable. If you want this to be the current date then set the variable to be equal to UTCTODAY()

 

Current Week = 
VAR _Today =
    DATE ( 2018, 1, 8 )
VAR _StartOfWeek =
    _Today - WEEKDAY ( _Today, 2 ) + 1
VAR _EndOfWeek =
    _Today
        + ( 7 - WEEKDAY ( _Today, 2 ) )
RETURN
    IF (
        MAX ( Table1[date] ) >= _StartOfWeek
            && MAX ( Table1[date] ) <= _EndOfWeek,
        SUM ( Table1[loggedin] ),
        BLANK ()
    )

@Anonymous great, thank you! I learned something new 🙂

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

Power BI Dev Camp Session 25 with aka link 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, August 25 at 11a PDT for a great session with Ted Pattison!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors