Forum Discussion
Earlier Function
- 6 years ago
how exactly do you filter by product? show please full wrong sentence.
in the most common case it can look like
CACLCULATE(SUM(TABLE[QTY]), FILTER(TABLE, DATEADD(TABLE[DATE].[Date],1,YEAR)=EARLIER(TABLE[DATE].[Date]) && TABLE[Product] = EARLIER(TABLE[Product]) ) ) - 6 years ago
amaniramahi , Try a new column like
sumx(filter(Table,Table[Product] =earlier(Table[Product]) && year(Table[Date]) = year(earlier(Table[Date]))-1),TABLE[QTY])
Measure
example with 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"))refer blog -https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184
Appreciate your Kudos.
Hi az38 , I tried your formula, it gives me blank for all column 😞
maybe you need to clear all your context with ALL() function, like
CALCULATE(SUM(TABLE[QTY]),
FILTER(ALL(TABLE),
DATEADD(TABLE[DATE].[Date],1,YEAR)=EARLIER(TABLE[DATE].[Date])
&&
TABLE[Product] = EARLIER(TABLE[Product])
)
)
otherwise, you have to check your data or provide us data example