cancel
Showing results 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

Frequent Visitor

## YTD of years until today

Hi! I'm looking to edit the TotalYTD function to show only the total of the period from the start of the year until today, but then copied in different years and compared tot the previous year.This would be:

date                                                     Sales     Diff

2016 (01/01/2016 - 06/18/2016)           1000

2017 (01/01/2017 - 06/18/2017)           2000    200%

2018 (01/01/2018 - 06/18/2018)           1000    50%

Can anoyone help me achieve this?

1 ACCEPTED SOLUTION
Resident Rockstar

Hi @wverheijen

I have made a test with your scenario to calculate the YTD sales between the period you required.

I created a Calendar Table with CALENDARAUTO and created one calculated column Today with the formula below, then I create the relationship with the two tables.

`Today = DATE(YEAR('Table'[Date]),MONTH(TODAY()),DAY(TODAY()))`

Besides, I created two measures to calculate the YTD.

The first formula is to calculate the YTD between the period.

```Measure =
TOTALYTD (
SUM ( 'Sheet22'[Sales] ),
'Table'[Date],
FILTER ( ALL ( 'Table'[Date] ), 'Table'[Date] <= MAX ( 'Table'[Today] ) )
)
```

Then we need to create another measure by if to determine the date.

`Measure 3 = IF(MAX('Table'[Date])<=MAX('Table'[Today]),[Measure],BLANK())`

Here is my test result.

For more details, you could refer to my attachment.

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 REPLIES 6
Super User

What does your original data look like and do you have a date table?

Also, you might want to check out my time intelligence quick measure here:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Frequent Visitor

Thanks for your reply! I've been working with the Time Intelligence function that you sent, this has helped me calculate the difference from years before. Yet I am facing one more problem.

this is my current result:

I need the Total_YTD column to calculate total from the start of the year until today's date. this is my DAX code:

```Total_YTD = TOTALYTD(SUM(Factuurregels[Regelbedrag]);Factuurregels[Datum].[Date];
FILTER(Factuurregels;
Factuurregels[Datum].[MonthNo] <= MONTH(TODAY())
&& Factuurregels[Datum].[Day] <= DAY(TODAY())
)
)```

2 issues appear here:

1. The values don't add up

2. it's calculating dates 1 till today for every month,  I want to see the YTD value of the full months until today's date. Wish I could just apply this:

`TOTALYTD(SUM(Factuurregels[Regelbedrag]);Factuurregels[Datum].[Date];ALL(Factuurregels[Datum].[Date];TODAY())`

Hope someone can help me!

Resident Rockstar

Hi @wverheijen

I have made a test with your scenario to calculate the YTD sales between the period you required.

I created a Calendar Table with CALENDARAUTO and created one calculated column Today with the formula below, then I create the relationship with the two tables.

`Today = DATE(YEAR('Table'[Date]),MONTH(TODAY()),DAY(TODAY()))`

Besides, I created two measures to calculate the YTD.

The first formula is to calculate the YTD between the period.

```Measure =
TOTALYTD (
SUM ( 'Sheet22'[Sales] ),
'Table'[Date],
FILTER ( ALL ( 'Table'[Date] ), 'Table'[Date] <= MAX ( 'Table'[Today] ) )
)
```

Then we need to create another measure by if to determine the date.

`Measure 3 = IF(MAX('Table'[Date])<=MAX('Table'[Today]),[Measure],BLANK())`

Here is my test result.

For more details, you could refer to my attachment.

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Helper III

@v-piga-msft thanks a lot for your solution! very very useful! 😀

Anonymous
Not applicable

Sorry but in your example the total field is blank! How can i show the total value? (in your example should be 18721 for 2016).

Thank you!

Frequent Visitor

Amazing! This is exactly what I needed and it works perfectly!

Announcements

#### 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.

#### Power BI Monthly Update - August 2024

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

#### Fabric Community Update - August 2024

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

Top Solution Authors
Top Kudoed Authors