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
Anonymous
Not applicable

DAX to Remove Column Duplicates and Deliver Expected SUM for Total for a Column

Community,

I am in need of help on removing a duplicate row to deliver the correct calculation I am seeking. Any help with a DAX solution to this much appreciated. I have provided a sample of the issues below as well as a sample file.

 

In this sample I have 3 tables, they are;

Weightings, CarConfig, and ForceDataduplicates2.JPG

In the table below I have added columns representing elements of the 3 tables. The data has been filtered by "TestID" and "Weighted ID"

Also included in the table is a measure created to calculate the "Weighted Value" of the "Data" for each "Attitude ID".

The measure is:

Weighted Value =
var item1 = SUM(ForceData[Data])
var item2 = MIN(Weightings[Weighting])
return
item1 * item2
duplicates3.JPG

In this example I would like to have the duplicate of the "Attitude ID" (in this case attitude ID 1) removed before the calculations are completed.

Also, I would like for the the "Weighted Value" to show the SUM of that column (this should be 16).

 

Below is a link to the PBIX file.

PBIX FILE

 

Thanks for any assistance offered!!

1 ACCEPTED SOLUTION

In order to easily identify rows which should be removed, create a new calculated column like this

repeatTestFlag =
IF (
    CarConfig[RunID]
        = CALCULATE (
            MAX ( CarConfig[RunID] );
            FILTER ( CarConfig; CarConfig[TestID] = EARLIER ( CarConfig[TestID] ) )
        );
    1;
    0
)

Then change the Weighted Value-measure to this:

Weighted Value =
SUMX (
    CarConfig;
    CALCULATE ( SUM ( ForceData[Data] ); CarConfig[repeatTestFlag] = 0 )
        * CALCULATE ( MIN ( Weightings[Weighting] ); CarConfig[repeatTestFlag] = 0 )
)

This removes the repeated row from the calculation, if you want to remove it from the table as well, add the column repeatTestFlag to the visual filter-pane of the visual and remove the rows where repeatTestFlag=1

 

View solution in original post

3 REPLIES 3
sturlaws
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

[Attitude ID] = 1 occurs twice in your table because there are two different RunIDs for this [Attitude ID], 1 and 5, for your filter selection([TestID]=1,00 and [Weighted ID]=1). If you remove RunID from your visual, [Attitude ID] = 1 is no longer repeated. If this is not what you are looking for, could please state how you want to handle different RundIDs

 

 

 

cheers

In order to easily identify rows which should be removed, create a new calculated column like this

repeatTestFlag =
IF (
    CarConfig[RunID]
        = CALCULATE (
            MAX ( CarConfig[RunID] );
            FILTER ( CarConfig; CarConfig[TestID] = EARLIER ( CarConfig[TestID] ) )
        );
    1;
    0
)

Then change the Weighted Value-measure to this:

Weighted Value =
SUMX (
    CarConfig;
    CALCULATE ( SUM ( ForceData[Data] ); CarConfig[repeatTestFlag] = 0 )
        * CALCULATE ( MIN ( Weightings[Weighting] ); CarConfig[repeatTestFlag] = 0 )
)

This removes the repeated row from the calculation, if you want to remove it from the table as well, add the column repeatTestFlag to the visual filter-pane of the visual and remove the rows where repeatTestFlag=1

 

Anonymous
Not applicable

Thanks!! This will work

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.