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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
mbunchj8
New Member

Dax formula to select a row based on multiple criteria and eliminate duplicates

Hello - I am learning Dax and I am stuck with filtering a table and removing duplicates.  I wish to filter the table to show the latest version of a contract, by contract id.

 

My table consist of the following:

Contract ID |  Supplier | version | Descr | Begin Date | Expire Date | Max Amount | Line Released Amount | Contract Line number.

 

mbunchj8_2-1730937653748.png

 

 

I want a Dax formula that will return one line per Contract ID based on the latest version # of the contract.

 

I am looking for  the formula to return the data I manually highlighted in yellow.  Is this possible?

 

Thank You -

 

3 ACCEPTED SOLUTIONS
FreemanZ
Super User
Super User

hi @mbunchj8 ,

 

we can do with DAX, but it is more advisible to do with Power Query.

Try with Power Query:

1. sort by version column,

2. then select Contract ID column, remove duplicate rows

View solution in original post

Anonymous
Not applicable

Hi @mbunchj8 ,

 

I've made a a test for your reference:

1\I assume there is a table

vbofengmsft_0-1730946822584.png

2\Add a new caculate table

vbofengmsft_1-1730946850963.png

 

FilteredTable = 
    FILTER(
        'YourTableName',
        'YourTableName'[Version] = 
            CALCULATE(
                MAX('YourTableName'[Version]),
                ALLEXCEPT('YourTableName', 'YourTableName'[Contract ID])
            )
    )

 

vbofengmsft_2-1730946885771.png

 

Best Regards,

Bof

 

View solution in original post

Poojara_D12
Super User
Super User

Hey @mbunchj8 ,

Hope you're doing good!

Here's what I have for you.
DAX:-

LatestContracts =
VAR LatestVersionPerContract =
    SUMMARIZE(
        'Contracts', 
        'Contracts'[Contract ID], 
        "LatestVersion", MAX('Contracts'[Version])
    )
RETURN
    FILTER(
        'Contracts',
        'Contracts'[Version] = LOOKUPVALUE(
            LatestVersionPerContract[LatestVersion],
            LatestVersionPerContract[Contract ID], 'Contracts'[Contract ID]
        )
    )

This formula will return a table with one row per CONTRACT ID showing only the latest version for each contract.

Please let me know if it helps you solve your problem.

 

Regards,
Poojara.

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

View solution in original post

5 REPLIES 5
Poojara_D12
Super User
Super User

Hey @mbunchj8 ,

Hope you're doing good!

Here's what I have for you.
DAX:-

LatestContracts =
VAR LatestVersionPerContract =
    SUMMARIZE(
        'Contracts', 
        'Contracts'[Contract ID], 
        "LatestVersion", MAX('Contracts'[Version])
    )
RETURN
    FILTER(
        'Contracts',
        'Contracts'[Version] = LOOKUPVALUE(
            LatestVersionPerContract[LatestVersion],
            LatestVersionPerContract[Contract ID], 'Contracts'[Contract ID]
        )
    )

This formula will return a table with one row per CONTRACT ID showing only the latest version for each contract.

Please let me know if it helps you solve your problem.

 

Regards,
Poojara.

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Poojara_D12  
 
I am trying to incorporate the formula you have into the Power Querry.  I thinmk I am entering it in the wrong maner.
Where do I insert the formula?
 
Table  QuerryTable QuerryAdvanced EditorAdvanced Editor
Anonymous
Not applicable

Hi @mbunchj8 ,

 

I've made a a test for your reference:

1\I assume there is a table

vbofengmsft_0-1730946822584.png

2\Add a new caculate table

vbofengmsft_1-1730946850963.png

 

FilteredTable = 
    FILTER(
        'YourTableName',
        'YourTableName'[Version] = 
            CALCULATE(
                MAX('YourTableName'[Version]),
                ALLEXCEPT('YourTableName', 'YourTableName'[Contract ID])
            )
    )

 

vbofengmsft_2-1730946885771.png

 

Best Regards,

Bof

 

FreemanZ
Super User
Super User

hi @mbunchj8 ,

 

we can do with DAX, but it is more advisible to do with Power Query.

Try with Power Query:

1. sort by version column,

2. then select Contract ID column, remove duplicate rows

FreemanZ -

 

I thought I would try a solution that seemed the easiest first.  When I followed your instructions and sorted the table by Contract Version (Highest to lowest).  It looked good.  I had a contract with version 08 on top of the list.  

 

I then went to the Contract ID Column and selected "Remove Duplicates".  Thios removed the duplicate contract IDs but it left  only the version 01 contract ID lines.  I did not get the version 08 or any other version besides version 01.

 

I wish this worked but I am not being left with the latest (highest contract version) as my result.

 

Thank You -

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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