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
jyeager
Helper I
Helper I

Historical YTD Aggregation Through Current Period of Each Year

Good morning! Can any of you nice smart people help me out or point me in the right direction that will help me design a measure to look at previous years-to-date aggregations? Here are the details:

 

I would like to show year-to-date hours charged for multiple years back but show the historical year through the current period in the year. For example: 

9/18/20: 200 hours

9/18/19: 175 hours

9/18/18: 225 hours ..... etc.

 

The issue I am encountering is that my previous years-to-date run through 12/31 of each year. Any thoughts?? I have provided my DAX below and an annotated graphic. I used the solution posted in this great post, but while it was giving me last years tot hours, it was still showing through 12/31. Maybe this isnt possible in the way I want to show it but I figured I would reach out to get everyone's throughts. Thanks in advance!!

 

Here is the measure I have in the graphic below:

 

 

hours YTD = CALCULATE(SUM(his_timecard[hours]),DATESYTD(date_table[Date]))

 

 

 

Below is the visual with some annotations:

 

Capture.PNG

 

 

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

Hi, @jyeager 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

k1.png

 

You may create measures as below.

Year to Date = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        [Date]>=DATE(YEAR(TODAY()),1,1)&&
        [Date]<=TODAY()
    )
)

Year to Date previous 1 year = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        [Date]>=DATE(YEAR(TODAY())-1,1,1)&&
        [Date]<=DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))
    )
)

Year to Date previous 2 year = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        [Date]>=DATE(YEAR(TODAY())-2,1,1)&&
        [Date]<=DATE(YEAR(TODAY())-2,MONTH(TODAY()),DAY(TODAY()))
    )
)

 

Result:

k2.png

 

Best Regards

Allan

 

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

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @jyeager 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

k1.png

 

You may create measures as below.

Year to Date = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        [Date]>=DATE(YEAR(TODAY()),1,1)&&
        [Date]<=TODAY()
    )
)

Year to Date previous 1 year = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        [Date]>=DATE(YEAR(TODAY())-1,1,1)&&
        [Date]<=DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))
    )
)

Year to Date previous 2 year = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        [Date]>=DATE(YEAR(TODAY())-2,1,1)&&
        [Date]<=DATE(YEAR(TODAY())-2,MONTH(TODAY()),DAY(TODAY()))
    )
)

 

Result:

k2.png

 

Best Regards

Allan

 

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

VijayP
Super User
Super User

@jyeager 

 

To get Last Year YTD you need to create another Dax

Last Year Hours =

Calculate (SUM(his_timecard[hours]),DATEADD(Date_Table[Date],-1,Year]))

For Previous to Previous Year the Function will be Calculate (SUM(his_timecard[hours]),DATEADD(Date_Table[Date],-1,Year]))

and then

For LY YTD = Calculate(Last Year Hours,DATESYTD(Date_Table[Date]) 

for LY to LY  = Calculate(Previous to Previous Year Hours,DATESYTD(Date_Table[Date])

 

Hope this helps ! Please mention this as Solution if you are good with it and Share your  Kudos

Regards

Vijay Perepa




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


amitchandak
Super User
Super User

@jyeager , Try like

 

hours YTD =
var _max = maxx(allselected(his_timecard), his_timecard[Date]) // Date from you table check , max date. use correct one
return
if(min(date_table[Date])<_max, CALCULATE(SUM(his_timecard[hours]),DATESYTD(date_table[Date])), blank())

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.