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

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

Reply
amaniramahi
Helper V
Helper V

Earlier Function

Hi,

 

I have the following table

 

ProductDateQtyPrevious Year Results
AAA1/1/20175 
BBB1/1/20173 
CCC1/1/20173 
AAA1/3/20178 
BBB1/3/20174 
CCC1/3/20176 
CCC1/9/20177 
AAA1/1/20186 
CCC1/1/20187 
BBB1/3/20187 
CCC1/9/20188 
AAA1/1/20199 
BBB1/3/20196 
CCC1/9/20197 

 

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

2 ACCEPTED SOLUTIONS
az38
Community Champion
Community Champion

@amaniramahi 

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])
)
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

amitchandak
Super User
Super User

@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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  why should I filter only on YEAR? there are many dates within the same year 😞

Thank you both, I worked for both solutions

az38
Community Champion
Community Champion

@amaniramahi 

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])
)
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hi @az38 , I tried your formula, it gives me blank for all column 😞

az38
Community Champion
Community Champion

@amaniramahi 

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


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.