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
CatManKuhn
Helper II
Helper II

YTD and Prior Years to Date Measure

Hi all,

 

I am strugging with a YTD measure. I would like to show a chart with Year as my legend and Month as my X-axis. I am struggling to remove the values for months that are greater than the month of the max date in my date table (essentially today). My goal is to remove the horizontal lines on the chart. I should see dots for the month of January since we are 4 days into the month. 

 

Here is my current DAX measure:

 

External Hires YTD = VAR MaxDay =
    CALCULATE (
        MAX ( 'Date'[Day of Year] ),
        ALL( 'Date' ),
        'Date'[CurrentDayOffset] = 0
    )
RETURN
    TOTALYTD (
        CALCULATE ( [External Hires], 'Date'[Day of Year] <= MaxDay ),
        'Date'[Date]
    )

 

 

Here is the visual and a matrix to better represent what I want to omit. I do not want the YTD values for prior years to repeat into "future" months.

 

CatManKuhn_0-1641324483758.png

Here is the current matrix:

Month

201620172018201920202021
January2813314410650215
February2813314410650215
March2813314410650215
April2813314410650215
May2813314410650215
June2813314410650215
July2813314410650215
August2813314410650215
September2813314410650215

 

Here is what the ideal outcome:

Month

201620172018201920202021
January2813314410650215

 

I'll of course play around with new visuals as the dots are not the best when there is only one month in the year so far. 

 

Thanks in advance!!

1 ACCEPTED SOLUTION

Hi, @CatManKuhn 

You can create a measure as below and apply it to 'Filters on this visual'.

filter = IF(MONTH(TODAY())<MONTH(MAX('Table'[Date])),0,1)

83.png

Please check my sample file for more details.

 

Best Regards,
Community Support Team _ Eason

View solution in original post

7 REPLIES 7
AlexisOlson
Super User
Super User

Does adding KEEPFILTERS help?

[...]
CALCULATE ( [External Hires], KEEPFILTERS ( 'Date'[Day of Year] <= MaxDay ) ),
[...]

 

Thanks @AlexisOlson. I tried this, but no change. Really appreciate you for taking a look at this.

OK. I think there's a hidden ALL inside the TOTALYTD since that's just syntactic sugar where

TOTALYTD ( [Measure], 'Date'[Date] )

is actually equivalent to this:

CALCULATE (
    [Measure],
    FILTER (
        ALL ( 'Date'[Date] ),
        'Date'[Date] <= MAX ( 'Date'[Date] )
            && YEAR ( 'Date'[Date] ) = YEAR ( MAX ( 'Date'[Date] ) )
    )
)

 

I'd recommend eliminating TOTALYTD entirely and trying something like this:

External Hires YTD =
VAR MaxDay =
    CALCULATE (
        MAX ( 'Date'[Day of Year] ),
        ALL ( 'Date' ),
        'Date'[CurrentDayOffset] = 0
    )
VAR MaxMonth =
    CALCULATE (
        MAX ( 'Date'[Month] ),
        'Date'[Day of Year] = MaxDay
    )
RETURN
    CALCULATE (
        [External Hires],
        'Date'[Day of Year] <= MaxDay,
        KEEPFILTERS ( 'Date'[Month] <= MaxMonth ),
        VALUES ( 'Date'[Year] )
    )
VahidDM
Super User
Super User

Hi @CatManKuhn 

 

Can you post sample data as text?

please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4. Relation between your tables

Appreciate your Kudos!!
LinkedIn:www.linkedin.com/in/vahid-dm/

Thank you! I have updated my post.

Hi, @CatManKuhn 

You can create a measure as below and apply it to 'Filters on this visual'.

filter = IF(MONTH(TODAY())<MONTH(MAX('Table'[Date])),0,1)

83.png

Please check my sample file for more details.

 

Best Regards,
Community Support Team _ Eason

I really like this method. Is it possible to revise this to the day level rather than month? For example, since today is February 1st I would want to show the YTD hires for all years as of 2/1.

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