Forum Discussion

sujesth's avatar
sujesth
New Member
3 years ago
Solved

Combining two rows with same ID, but selecting only one

Hi,

 

I'm having some trouble combining rows for products that have the same ID. What I am trying to do is have just one line item for a product that appears more than once in my table.

 

Current Table Sample

REFYEARPRODUCTCOSTPERSON
A12023Pears $       1.50Bob
B22023Apples $       1.30Bob
B22023Red Apples $       1.30Jane
 2023Oranges $       1.00Jane
C262024Green Lime $       1.10Bob
C262024Lime $       1.10Lisa

- not all the items have a REF

- the product name may be a little different, but the REF and COST are really what I need to focus on. 

 

Desired Table Sample

REFYEARPRODUCTCOSTPERSON
A12023Pears $       1.50Bob
B22023Red Apples $       1.30Jane
 2023Oranges $       1.00Jane
C262024Lime $       1.10Lisa

 

I'm not able to essentially "eliminate" a row. Calculated columns don't give me what I need and I've been unsuccessful with measures.  This is the latest measure I used, but this just repeats the cost value. Not sure what I'm doing wrong here. 

 

Product_Cost = VAR COST = ADDCOLUMNS('MyTable', "ActualCost", CALCULATE(MAX('MyTable'[Cost]), GROUPBY('MyTable','MyTable'[Ref]))) RETURN MAXX(COST, IF('MyTable'[Cost] = [ActualCost], 'MyTable'[Cost],0))

 

Any help will be very much appreciated! Thank you!

3 Replies

  • Arul's avatar
    Arul
    Icon for Super User rankSuper User

    sujesth ,

    Try this as a calculated table,

     

    Test Table = 
    VAR _tempTable = 
    SUMMARIZE(
        'Table',
        'Table'[REF],
        "Year",MAX('Table'[YEAR]),
        "Product",MAX('Table'[PRODUCT]),
        "Cost",MAX('Table'[COST]),
        "Name",MAX('Table'[PERSON])
        )
    RETURN _tempTable

     

    Thanks,

    Arul