Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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:
What am I doing wrong here?
Solved! Go to Solution.
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
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:
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.
@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())
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
84 | |
76 | |
73 | |
42 | |
36 |
User | Count |
---|---|
109 | |
56 | |
52 | |
48 | |
42 |