I have a table, let's call it Products
with columns:
Id
ProductId
Version
- some other columns…
Id
column is the primary key, and ProductId
groups rows. Now I want to view distinct values of ProductId
where Version
is highest.
I.e. From data set:Id
| ProductId
| Version
| ...100
| 1
| 0
| ...101
| 2
| 0
| ...102
| 2
| 1
| ...103
| 2
| 2
| ...
I need to get:Id
| ProductId
| Version
| ...100
| 1
| 0
| ...103
| 2
| 2
| ...
In SQL I would write:
SELECT Id, ProductId, Version, OtherColumns
FROM Products p1
WHERE NOT EXISTS
(SELECT 1
FROM Products p2
WHERE p2.ProductId = p1.ProductId
AND p2.Version > p1.Version)
But I have no idea how to express this in DAX. Is this approach with subqueries inapplicable in PowerBI?