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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors