Forum Discussion
Last Year Year To Date summarized
Hi,
I am new to Power BI and struggling my way to find a way to calculate a total amount of sales YTD last year.
I have a table containing sales and dates (incomplete) and another table containing dates (marked as date table), which is complete. I my date table I also have a column with YTD - dates.
What I want is to generate a total YTD compared to YTD last year.
Hi JWT ,
Please try the following formula:
Sales YTD LY = IF ( HASONEVALUE ( Periode[Måned] ), IF ( [Sales YTD] <> BLANK (), CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( Periode[Dato] ) ) ), CALCULATE ( [Total Sales], DATESBETWEEN ( Periode[Dato], EDATE ( MIN ( Periode[Dato] ), -12 ), EOMONTH ( MAX ( Sales[Date] ), -12 ) ) ) )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
8 Replies
- amitchandak
Super User
JWT , You should try measure like these with help from date table
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA - JWTFrequent Visitor
HI amitchandak , thank you for your reply.
I have written as you suggest:
Sales YTD = CALCULATE(SUM(Sales[Sales Price Base Exchange Total]),DATESYTD(Periode[Dato], "12/31"))and
Sales YTD LY = CALCULATE(SUM(Sales[Sales Price Base Exchange Total]),DATESYTD(DATEADD(Periode[Dato],-1,YEAR),"12/31"))This is now the result:
It seems to accumulate YTD sales, but doesnt give me a total. YTD LY seems also to accumulate, but returns TY total as total LY? Also, LY data does not seem to "stop counting" for future dates.
- amitchandak
Super User
JWT , when use YTD and you do not have a date filter, it will take the last date in the calendar to calculate YTD. So it is better to select date or range .
Other wise based on today's date, with a filter
YTD Today=
var _min = date(year(today()),1,1)
var _day = today()
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _day) )LYTD =
var _min = date(year(today())-1,1,1)
var _max = date(year(today())-1,month(today()),day(today()))
var _day = datediff(_min, _max,day)+1
return
CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year] = year(Today())-1 && 'Date'[Day of Year] <= _max))Refer, Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5bd4- JWTFrequent Visitor
Since I need the measure to be used in other calculations, I need the filter to be within the calculation (If that makes sense).
As stated, I also have a date column only returning dates for dates in this year until now. Can I use this in the date reference instead?
For instance, this gives me the correct result for YTD:
Sales YTD = CALCULATE(SUM(Sales[Sales Price Base Exchange Total]),DATESYTD(Periode[YTD], "12/31"))but it doesnt work for LYTD:
LYTD = CALCULATE(SUM(Sales[Sales Price Base Exchange Total]),DATESYTD(DATEADD(Periode[YTD],-1,YEAR),"12/31"))