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

Hi guys,

 

Just need some advice,

Fristly I want to create 2 visualization for amount YTD and YTD Last Year : 

1. Clustered Column chart

2. Area chart

 

So I created this 2 measures :

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

and 

Value YTD Prior= CALCULATE([Inventory value YTD], SAMEPERIODLASTYEAR('Date'[DateKey]))
 
At first it was ok, here are the result:
image.png
 
image.png
 
But then I realized the area chart doesn't look correct, since the last value (March2019) will be drag over to the future month.
 
So I did some changes on the measure for YTD ->
Value YTD =
IF(LASTDATE('Date'[DateKey]) > TODAY(), BLANK(), TOTALYTD(SUM('inventory'[value]),'inventory'[DateKey]))
 
It will give blank to future dates, and it looks correct to my area chart :
image.png
 
but of course it will make my column chart false, since there is no Date dimension over there.
My YTD measure is blank now in column chart.
 
Is that mean I cannot use the same measure ? or the way I did is wrong ?
 
Thanks in advance,
 
 
 
 
1 ACCEPTED SOLUTION

Hi @admin_xlsior ,

 

Please Update the two measures as below.

 

Value YTD = 
IF (
    ISBLANK ( [Value YTD Prior] ),
    BLANK (),
    TOTALYTD ( SUM ( 'Table'[value] ), 'Table'[Date] )
)
Value YTD Prior = 
VAR Yearmonth =
    YEAR ( MAX ( 'Table'[Date] ) ) * 100
        + MONTH ( MAX ( 'Table'[Date] ) )
VAR todayym =
    YEAR ( TODAY () ) * 100
        + MONTH ( TODAY () )
RETURN
    IF (
        Yearmonth > todayym,
        BLANK (),
        CALCULATE (
            TOTALYTD ( SUM ( 'Table'[value] ), 'Table'[Date] ),
            SAMEPERIODLASTYEAR ( 'Table'[Date] )
        )
    )

ytd.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

3 REPLIES 3
v-frfei-msft
Community Support
Community Support

Hi @admin_xlsior ,

 

One sample for your reference. Please check the following steps as below.

 

1. Create a date table as below and create relationshp between it and the fact table.

 

date = CALENDAR(DATE(2018,01,01),DATE(2019,12,31))

2. To create measures as below.

 

Value YTD = TOTALYTD(SUM('Table'[value]),'Table'[Date])
Value YTD Prior = CALCULATE([Value YTD], SAMEPERIODLASTYEAR('Table'[Date]))

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thanks for replying,

 

Forgive me if I mistaken, but I think your step no 2 is incorrect. Is it not supposed to use your Date Dimension ?

Value YTD = TOTALYTD(SUM('Table'[value]),'Date'[Date])

 

Since if I tried to use the transaction table's date, it will give me the total amount per month instead accumulative.

 

Anyway this is the "final" which I can get the correct result :

Value YTD = TOTALYTD(SUM('Inventory'[value]),'Date'[DateKey])
Value YTD Prior = CALCULATE([Value YTD], SAMEPERIODLASTYEAR('Date'[DateKey]))

 

By that I get this result :

image.png

The left table is from the original data with no measures.

However, still, there are 2 question I' confuse :

1. Although my table has data up to Dec 2019, TotalYTD supposed to total up to today only, right ?

2. At the visualization, it will give me this :

image.png

As point no 1, the value starting May 2019, should be flat ( because that is the value up to today). Even so, I also wants the visual to stop displaying the value for the May 2019 onwards. (that is why in my first message, I've added if bigger than todays date, it is BLANK(). But then we have the same issue which I stated in my first message.

 

Thanks,

 

 

 

 

 

 

 

 

 

 

 

 

Hi @admin_xlsior ,

 

Please Update the two measures as below.

 

Value YTD = 
IF (
    ISBLANK ( [Value YTD Prior] ),
    BLANK (),
    TOTALYTD ( SUM ( 'Table'[value] ), 'Table'[Date] )
)
Value YTD Prior = 
VAR Yearmonth =
    YEAR ( MAX ( 'Table'[Date] ) ) * 100
        + MONTH ( MAX ( 'Table'[Date] ) )
VAR todayym =
    YEAR ( TODAY () ) * 100
        + MONTH ( TODAY () )
RETURN
    IF (
        Yearmonth > todayym,
        BLANK (),
        CALCULATE (
            TOTALYTD ( SUM ( 'Table'[value] ), 'Table'[Date] ),
            SAMEPERIODLASTYEAR ( 'Table'[Date] )
        )
    )

ytd.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others 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.

Top Solution Authors