cancel
Showing results for
Did you mean:
Highlighted
Helper I

## Sum between two dates, ignoring the dates before my start of the year

Hello,

I have to calculate a SUM of my new clients between two dates.

- The date I choose from my filter

- The first day of the year of the date I choose from my filter

So for example, the date I choose from my filter is 23/05/2020. So my SUM has to be between 1/01/2020 and 23/05/2020. This SUM doesn't have to include all the dates before 1/01/2020.

So I did something like that:

Measure = CALCULATE(SUM('Table'[MY_NEW_CLIENTS);FILTER(ALLEXCEPT('TABLE';'TABLE'[CLIENT_TYPE_ID]); 'TABLE'[DATE] >= STARTOFYEAR('TABE'[DATE])&&'TABLE'[DATE] <=SELECTEDVALUE('TABLE'[DATE])))

The issue is, this measure also gives me the sum of all dates before my startoftheyear, whilst it should return only the sum between 1/01/2020 and 23/05/2020

Any ideas?

Thank you

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Super User IV

## Re: Sum between two dates, ignoring the dates before my start of the year

Perhaps:

``````Measure =
VAR __Date = SELECTEDVALUE('Table'[DATE])
VAR __First = DATE(YEAR(__Date),1,1)
RETURN
SUMX(FILTER('Table',[DATE] >= __First && [DATE] <= __Date),[MY_NEW_CLIENTS])``````

---------------------------------------

Putting square pegs in round holes since 1972.

##### I have a NEW book! DAX Cookbook from Packt
Over 120 DAX Recipes!

Proud to be a Super User!

Highlighted
Community Support

## Re: Sum between two dates, ignoring the dates before my start of the year

Hi @MCacc ,

You may create measure like DAX below.

``````Measure =

Var _FilterDate= SELECTEDVALUE( 'TABE'[DATE])

Var _FirstDate= DATE(YEAR ( 'TABE'[DATE]) , 1,1)

Return

CALCULATE(SUM('Table'[MY_NEW_CLIENTS),FILTER(ALLEXCEPT('TABLE', 'TABLE'[CLIENT_TYPE_ID]), 'TABLE'[DATE] >= _FirstDate&&'TABLE'[DATE] <=_FilterDate))``````

Best Regards,

Amy

Community Support Team _ Amy

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

3 REPLIES 3
Highlighted
Super User IV

## Re: Sum between two dates, ignoring the dates before my start of the year

Perhaps:

``````Measure =
VAR __Date = SELECTEDVALUE('Table'[DATE])
VAR __First = DATE(YEAR(__Date),1,1)
RETURN
SUMX(FILTER('Table',[DATE] >= __First && [DATE] <= __Date),[MY_NEW_CLIENTS])``````

---------------------------------------

Putting square pegs in round holes since 1972.

##### I have a NEW book! DAX Cookbook from Packt
Over 120 DAX Recipes!

Proud to be a Super User!

Highlighted
Super User IV

## Re: Sum between two dates, ignoring the dates before my start of the year

@MCacc , is that not YTD ?

Example

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...

My Recent Blog -Week is not so Weak Connect on Linkedin

Proud to be a Super User!

Highlighted
Community Support

## Re: Sum between two dates, ignoring the dates before my start of the year

Hi @MCacc ,

You may create measure like DAX below.

``````Measure =

Var _FilterDate= SELECTEDVALUE( 'TABE'[DATE])

Var _FirstDate= DATE(YEAR ( 'TABE'[DATE]) , 1,1)

Return

CALCULATE(SUM('Table'[MY_NEW_CLIENTS),FILTER(ALLEXCEPT('TABLE', 'TABLE'[CLIENT_TYPE_ID]), 'TABLE'[DATE] >= _FirstDate&&'TABLE'[DATE] <=_FilterDate))``````

Best Regards,

Amy

Community Support Team _ Amy

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

Announcements

#### August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

#### Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

#### Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

#### Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.

Top Solution Authors
Top Kudoed Authors