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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
mikemarr3
Frequent Visitor

Returning Values from a column, based on their being duplicate values in another column

Hey there,

 

Im trying to create a custom column that would display a value from another column, based on the fact that I found duplicate values in a 3rd column.

 

In this below sample data set, I have an ID row, which will contain duplicates, I then have a column that displayed the amount of times that ID is found in the table, I have a fruit column, and I have a time column that would represent a modified timestamp, then I have the custom desired output column Id like.

 

I want the custom column to check for count of ID, if its equal to 1, then output equals fruit, if its greater than 1, then find all the rows with the ID, and check the fruit column for the type of fruit, if the type of fruit is equal to banana or apple, then output is either banana or apple, and remianing rows for that ID the output would be blank. If the group of fruits from that group of IDs does not contain apple or banana, then display the fruit from the most recent modified record, and the others will be blank.

 

Please help. Ive spent so much time on this already and cant get it to work!. Thank you! 

 

mikemarr3_0-1702311960633.png

 

 

 

1 ACCEPTED SOLUTION
smpa01
Community Champion
Community Champion

@mikemarr3  you can do a measure like this

Measure = 
VAR tblOne =
    ALL ( 'Table' )
VAR tblTwo =
    VALUES ( 'Table'[id] )

//check for count of ID -- count of id by unique id    
VAR countID =
    CALCULATE ( COUNT ( 'Table'[id] ), tblOne, tblTwo ) 
VAR time =
    MAX ( 'Table'[time] )
//minTime by ID    
VAR minTime =
    CALCULATE ( MIN ( 'Table'[time] ), tblOne, tblTwo )
//maxTime by ID    
VAR mxTime =
    CALCULATE ( MAX ( 'Table'[time] ), tblOne, tblTwo )
// temp table of all fruits by ID    
VAR _right =
    SELECTCOLUMNS (
        SUMMARIZE (
            FILTER (
                tblOne,
                'Table'[id] = CALCULATE ( MAX ( 'Table'[id] ), tblOne, tblTwo )
            ),
            'Table'[fruit]
        ),
        "fruit", 'Table'[fruit] & ""
    )
// temp table for explicit checking    
VAR _left =
    DATATABLE ( "fruit", STRING, { { "banana" }, { "apple" } } )
//checks if fruit by id is either banana or apple    
VAR _join =
    NATURALINNERJOIN ( _left, _right )
// count the result of joins to determine if there is any zero match and remianing rows for that ID the output would be blank.   
// If the group of fruits from that group of IDs does not contain apple or banana, then display the fruit from the most recent modified record, and the others will be blank. 
VAR rowCount =
    COUNTROWS ( _join )
// if its greater than 1, then find all the rows with the ID, and check the fruit column for the type of fruit, if the type of fruit is equal to banana or apple, then output is either banana or apple    
VAR ternary =
    IF (
        rowCount >= 1
            && time == minTime,
        MAX ( 'Table'[fruit] ),
        IF ( rowCount == BLANK () && time == mxTime, MAX ( 'Table'[fruit] ) )
    )  
VAR final =
    IF ( countID = 1, MAX ( 'Table'[fruit] ), /*if its equal to 1, then output equals fruit */ ternary )
RETURN
    final

 

smpa01_0-1702321756219.png

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

View solution in original post

1 REPLY 1
smpa01
Community Champion
Community Champion

@mikemarr3  you can do a measure like this

Measure = 
VAR tblOne =
    ALL ( 'Table' )
VAR tblTwo =
    VALUES ( 'Table'[id] )

//check for count of ID -- count of id by unique id    
VAR countID =
    CALCULATE ( COUNT ( 'Table'[id] ), tblOne, tblTwo ) 
VAR time =
    MAX ( 'Table'[time] )
//minTime by ID    
VAR minTime =
    CALCULATE ( MIN ( 'Table'[time] ), tblOne, tblTwo )
//maxTime by ID    
VAR mxTime =
    CALCULATE ( MAX ( 'Table'[time] ), tblOne, tblTwo )
// temp table of all fruits by ID    
VAR _right =
    SELECTCOLUMNS (
        SUMMARIZE (
            FILTER (
                tblOne,
                'Table'[id] = CALCULATE ( MAX ( 'Table'[id] ), tblOne, tblTwo )
            ),
            'Table'[fruit]
        ),
        "fruit", 'Table'[fruit] & ""
    )
// temp table for explicit checking    
VAR _left =
    DATATABLE ( "fruit", STRING, { { "banana" }, { "apple" } } )
//checks if fruit by id is either banana or apple    
VAR _join =
    NATURALINNERJOIN ( _left, _right )
// count the result of joins to determine if there is any zero match and remianing rows for that ID the output would be blank.   
// If the group of fruits from that group of IDs does not contain apple or banana, then display the fruit from the most recent modified record, and the others will be blank. 
VAR rowCount =
    COUNTROWS ( _join )
// if its greater than 1, then find all the rows with the ID, and check the fruit column for the type of fruit, if the type of fruit is equal to banana or apple, then output is either banana or apple    
VAR ternary =
    IF (
        rowCount >= 1
            && time == minTime,
        MAX ( 'Table'[fruit] ),
        IF ( rowCount == BLANK () && time == mxTime, MAX ( 'Table'[fruit] ) )
    )  
VAR final =
    IF ( countID = 1, MAX ( 'Table'[fruit] ), /*if its equal to 1, then output equals fruit */ ternary )
RETURN
    final

 

smpa01_0-1702321756219.png

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.