We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi,
I have the following table
| Product | Date | Qty | Previous Year Results |
| AAA | 1/1/2017 | 5 | |
| BBB | 1/1/2017 | 3 | |
| CCC | 1/1/2017 | 3 | |
| AAA | 1/3/2017 | 8 | |
| BBB | 1/3/2017 | 4 | |
| CCC | 1/3/2017 | 6 | |
| CCC | 1/9/2017 | 7 | |
| AAA | 1/1/2018 | 6 | |
| CCC | 1/1/2018 | 7 | |
| BBB | 1/3/2018 | 7 | |
| CCC | 1/9/2018 | 8 | |
| AAA | 1/1/2019 | 9 | |
| BBB | 1/3/2019 | 6 | |
| CCC | 1/9/2019 | 7 |
in "Previous Year Results" column, I wanted to calculate the sold qty for the same day in the previous year AND for the same product
When I type the following formula, it filters the dates
CACLCULATE(SUM(TABLE[QTY]),FILTER(TABLE,DATEADD(TABLE[DATE].[Date],1,YEAR)=EARLIER(TABLE[DATE].[Date])))
it works and sums the qty sold in the same date in previous year (regardless the product)
but When I add another filter with earlier value in Product type it gives me blank.
I need help
Solved! Go to Solution.
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])
)
)
@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-Y...
Appreciate your Kudos.
@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-Y...
Appreciate your Kudos.
@amitchandak why should I filter only on YEAR? there are many dates within the same year 😞
Thank you both, I worked for both solutions
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])
)
)
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 57 | |
| 38 | |
| 33 | |
| 19 | |
| 16 |
| User | Count |
|---|---|
| 67 | |
| 66 | |
| 40 | |
| 34 | |
| 25 |