cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
AnthonyJoseph
Resolver III
Resolver III

check if item exists in the latest year

Hello,

 

I have a table visual and would like to display if the item that exists in the latest year (latest year in the data selected) by a measure.

 

Below is the sample data and expected output:

Unit table:  
ItemYearunit
Fruit2022100
Fruit2021200
Fruit2020500
Veggies2021100
Veggies202040
Meat2022150
Meat2021250

 

Expected output:  Here "Item exist in the latest selected year" is the output measure that will say whether the Item exists in the latest year (here 2022 is the latest or maximum year). If the item exists in the latest year then it should return "Yes" else if the item is not there in the latest year then it should be "No".

 

ItemYearunitItem exist in the latest selected year
Fruit2022100Yes
Fruit2021200Yes
Fruit2020500Yes
Veggies2021100No
Veggies202040No
Meat2022150Yes
Meat2021250Yes

 

Please can you let me know how to achieve this result.

 

Thanks,

AnthonyJoseph

1 REPLY 1
vicky_
Super User
Super User

Hello!
Try something like:

Exist in latest year = 
var latest = CALCULATE(MAX('Table'[Year]), ALLSELECTED('Table'))
var itemsInLatestYear = SELECTCOLUMNS(FILTER(ALL('Table'), 'Table'[Year] = latest), "Items", 'Table'[Item])
return IF(SELECTEDVALUE('Table'[Item]) in itemsInLatestYear, "Yes", "No")

 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors