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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
AnthonyJoseph
Resolver III
Resolver III

Display result only if prior year data is available

Hello Community,

 

I have a datatable where we have sales and profit for different items for different years.

Now, the ask is that "Sales" should be calculated only when the "Item name" exists for the previous year. Also, we dont have a date/calendar table.

 

Example:

When "A" is selected under "Item"  and "2022" is selected from Year silcer.  Sales value should be 100.

when Year "2021" is selected Sales should be 200 (Apple)+100 (Papaya) = 300

ItemItem nameYearSalesProfit
AApple2022100200
AApple2021200400
AApple20205001000
APapaya2021100400
APapaya202040160
VCucumber2022150500
VCucumber2021250800

 

Is it possible to achieve this in power bi - dax?

Thanks for your help in advance.

1 ACCEPTED SOLUTION
vapid128
Solution Specialist
Solution Specialist

add colnum
Item_exist_LastYear =
[Item] in
CALCULATETABLE(
    VALUES(table22[Item]),
    FILTER(
        ALL(table22),
        table22[Year]=EARLIER(table22[Year])-1
    )
)

View solution in original post

1 REPLY 1
vapid128
Solution Specialist
Solution Specialist

add colnum
Item_exist_LastYear =
[Item] in
CALCULATETABLE(
    VALUES(table22[Item]),
    FILTER(
        ALL(table22),
        table22[Year]=EARLIER(table22[Year])-1
    )
)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.