Forum Discussion

dguibert's avatar
dguibert
Frequent Visitor
1 year ago
Solved

How to copy values and concatenate based on cell values?

Hi,   I have Projects which are deployed with assets and I need to record for each project which assets have been sent to site. Sometimes the Project and Asset are repeated. I need to concatenate t...
  • burakkaragoz's avatar
    1 year ago

    Hi dguibert ,

     

    You can achieve this using Power BI's DAX with a calculated column and a bit of row context logic. Since you're working in the table view and not in Power Query, here's a way to do it:

    Try adding a calculated column like this:

    Result Desired = 
    VAR CurrentProject = [PROJECT]
    VAR CurrentAsset = [ASSET]
    RETURN
    CALCULATE(
        CONCATENATEX(
            FILTER(
                'YourTable',
                'YourTable'[PROJECT] = CurrentProject &&
                'YourTable'[Index] <= EARLIER('YourTable'[Index])
            ),
            'YourTable'[ASSET],
            ", "
        )
    )

    Important: You’ll need an Index column to preserve row order. You can add it in Power BI using "Add Index Column" in Power Query before loading the data.

    This will concatenate the assets for each project up to the current row, giving you the cumulative list you're looking for.

    Let me know if you need help adapting this to your exact table name or structure.

    If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

    This response was assisted by AI for translation and formatting purposes.

  • jgeddes's avatar
    1 year ago

    If you cannot access the query editor at all, either to do this in M or to add an index, you can try something like this as a calculated column...

    Result = 
    var _project = 
    [PROJECT]
    var _vTable = 
    SUMMARIZE(
        assetTable,
        assetTable[PROJECT],
        "__value", CONCATENATEX(DISTINCT(assetTable[ASSET]), [ASSET], ", ")
    )
    RETURN
    MINX(
        FILTER(_vTable, [PROJECT] = _project),
        [__value]
    )

     It should look like this...