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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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