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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. 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

v-bofeng-msft
Community Support
Community Support

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
Solution Sage
Solution Sage

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.

View solution in original post

5 REPLIES 5
Poojara_D12
Solution Sage
Solution Sage

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.

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
v-bofeng-msft
Community Support
Community Support

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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Top Solution Authors