Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Patryk_PL
New Member

Line graph with cut off point on TODAY()

Hi!

 

I'm working on a dashboard to show materials scrapped in current year YTD while trynig to simoultanously show previous year. I have created two measures:

ScrapLastYear = CALCULATE(SUM(Data[Amt.in loc.cur.]),SAMEPERIODLASTYEAR(Data[Posting Date].[Date])) to show whole previous year and second:
SumEndDayToday = CALCULATE(SUM(Data[Amt.in loc.cur.]),DATESYTD(Data[Posting Date]),MAX(Data[Posting Date],TODAY()))
The result is almost okay, but I can't figure out, what should be changed to show current year only up to end of data set (currently - beginning of July). Line graph is continuing the line in the future:
Patryk_PL_0-1626430428357.png

What am I doing wrong here?

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

Hi @Patryk_PL ,

 

Did you have a dim_date table in your date model. I suggest you create one and you can use the following measure:

 

ScrapLastYear =
VAR A =
    CALCULATE ( MAX ( Data[Posting Date] ), ALL ( Data ) )
RETURN
    IF (
        MAX ( Dim_Date[Date] ) <= A,
        CALCULATE (
            SUM ( Data[Amt.in loc.cur.] ),
            SAMEPERIODLASTYEAR ( Dim_Date[Date] )
        )
    )

SumEndDayToday =
VAR A =
    CALCULATE ( MAX ( Data[Posting Date] ), ALL ( Data ) )
RETURN
    IF (
        MAX ( Dim_Date[Date] ) <= A,
        CALCULATE ( SUM ( Data[Amt.in loc.cur.] ), DATESYTD ( Dim_Date[Date] ) )
    )

 

Use the date column from the dim_date table as x-axis.

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

4 REPLIES 4
v-deddai1-msft
Community Support
Community Support

Hi @Patryk_PL ,

 

Did you have a dim_date table in your date model. I suggest you create one and you can use the following measure:

 

ScrapLastYear =
VAR A =
    CALCULATE ( MAX ( Data[Posting Date] ), ALL ( Data ) )
RETURN
    IF (
        MAX ( Dim_Date[Date] ) <= A,
        CALCULATE (
            SUM ( Data[Amt.in loc.cur.] ),
            SAMEPERIODLASTYEAR ( Dim_Date[Date] )
        )
    )

SumEndDayToday =
VAR A =
    CALCULATE ( MAX ( Data[Posting Date] ), ALL ( Data ) )
RETURN
    IF (
        MAX ( Dim_Date[Date] ) <= A,
        CALCULATE ( SUM ( Data[Amt.in loc.cur.] ), DATESYTD ( Dim_Date[Date] ) )
    )

 

Use the date column from the dim_date table as x-axis.

 

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

 

Best Regards,

Dedmon Dai

Ok, it looks better when I've created separate Date table (from https://www.youtube.com/watch?v=F-GGF9OS5ys this video). Now I have something like this:

Patryk_PL_0-1627054135635.png

What else shall be changed? I've created measures like mentioned, but...

Ok, I found the issue - just entered a filter for current year and worked fine now.

amitchandak
Super User
Super User

@Patryk_PL , to me this does not seem like YTD

second, you should use only the date table

 

examples

 

YTD QTY forced=
var _max1 = today() //or maxx(allselected('Order'),'order'[Date])
var _max = format(_max,"MMDD")
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),filter('Date', format('Date'[Date],"MMDD")<=_max))


YTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESYTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

 

LYTD QTY forced=
var _max = date(year(today())-1,month(today()),day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

 

 

Same <= _max can use with a trailing measure or measure sameperiodlastyear

 

example

if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),SAMEPERIODLASTYEAR('Date'[Date])), blank())

 

if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),dateadd('Date'[Date],-1,year), blank())

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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