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
admin_xlsior
Post Prodigy
Post Prodigy

YTD and YTD Last Year

Hello, 

 

Just need some advice for my measures to calculate YTD and YTD Last Year.

Basically I want to create 2 visualization :

1. Column chart

2. Area chart

 

So I created these 2 measures:

Value YTD = TOTALYTD(SUM('Inventory'[value]),'Inventory'[DateKey]))

and 

Value YTD Prior = CALCULATE([Value YTD], SAMEPERIODLASTYEAR('Date'[DateKey]))

 

At first those were ok :

image.pngimage.png

 

But then I realized the area chart is incorrect, because it dragging the last value of March 2019 all the way to future months.

 

So I changed the YTD measures to be :

Value YTD = IF(LASTDATE('Dates'[DateKey] > TODAY(), BLANK(), TOTALYTD(SUM('Inventory'[value]),'Inventory'[DateKey])))

 

The area chart is correct now : 

image.png

 

 

But my column chart is false, obviously because it does not have Date dimension over there. So now it is blank

 

Should I create different measure for each visulization ? or the I did is wrong ?

 

Thanks in advance,

 

 

 

 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @admin_xlsior 

With these measures

ytd = 
TOTALYTD(SUM(Sheet1[sales]),Sheet1[date],FILTER('date',MONTH('date'[Date])<MONTH(TODAY())))

ly ytd = CALCULATE(TOTALYTD(SUM(Sheet1[sales]),Sheet1[date]),SAMEPERIODLASTYEAR('date'[Date]))

2.png3.png

 

 

In addition, TOTALYTD Evaluates the year-to-date value of the expression in the current context.

So the value is accumulated till the end of the year.

To get your line chart, you need replace TOTALYTD with TOTALMTD which Evaluates the value of the expression for the month to date, in the current context.

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @admin_xlsior 

Is this problem sloved? 

If it is sloved, could you kindly accept it as a solution to close this case?

If not, please let me know.

 

Best Regards

Maggie

v-juanli-msft
Community Support
Community Support

Hi @admin_xlsior 

With these measures

ytd = 
TOTALYTD(SUM(Sheet1[sales]),Sheet1[date],FILTER('date',MONTH('date'[Date])<MONTH(TODAY())))

ly ytd = CALCULATE(TOTALYTD(SUM(Sheet1[sales]),Sheet1[date]),SAMEPERIODLASTYEAR('date'[Date]))

2.png3.png

 

 

In addition, TOTALYTD Evaluates the year-to-date value of the expression in the current context.

So the value is accumulated till the end of the year.

To get your line chart, you need replace TOTALYTD with TOTALMTD which Evaluates the value of the expression for the month to date, in the current context.

 

Best Regards
Maggie

 

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

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.