Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Concatenatex with multiple criteria

Hey folks, I need some help with concatenatex - any help is greatly appreciated.

 

I have to concatenate the rows from the column "Completed At - Clusters" by all 3 other columns. Ultimatelly, I need the following outcome:

 

Original:

User IdYearMonthCompleted At - Clusters
360592019111
36474201952
36474201953
36474201954
36474201961
36474201962
36474201963
36474201964

 

Goal:

User IdYearMonthCompleted At - Clusters
360592019111
36474201952,3,4
36474201961,2,3,4
  • kentyler's avatar
    kentyler
    6 years ago

    use 

    Combined Column = VAR user_id = completed[User Id]
    VAR month_number = completed[Month]
    VAR completed_string = calculate(CONCATENATEX(completed,completed[Completed At - Clusters],","),ALL(completed),completed[User Id] = user_id, completed[Month] = month_number)
    RETURN completed_string
    the difference is that since a calculated column has a built in row context you no longer need to use "max" to get the user_id and month_number but can just refer to them directly

4 Replies

  • kentyler's avatar
    kentyler
    Icon for Solution Sage rankSolution Sage

    Here are my results




    I used a measure for this 
    Combined =
    VAR user_id =
        MAX ( completed[User Id] )
    VAR month_number =
        MAX ( completed[Month] )
    VAR completed_string =
        CALCULATE (
            CONCATENATEX ( completed, completed[Completed At - Clusters], "," ),
            ALL ( completed ),
            completed[User Id] = user_id,
            completed[Month] = month_number
        )
    RETURN
        completed_string
    I used VARIABLES to pull out the user id and month for each row. Then I used CONTATENATEX inside of CALCULATE. CALCULATE let me put filters on the completed table, first I applied ALL() so i would start with the whole table and not just the current row, then i used my variables to filter for month and user id

    This is a sample use of VAR as described here https://bislogans.com/6-use-simple-tricks/

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi kentyler ,

       

      Thank you for the help and thorough explanation. This table, however, will serve as source to other tables and I really need it as a column. How can I convert this measure into a column?

      • kentyler's avatar
        kentyler
        Icon for Solution Sage rankSolution Sage

        use 

        Combined Column = VAR user_id = completed[User Id]
        VAR month_number = completed[Month]
        VAR completed_string = calculate(CONCATENATEX(completed,completed[Completed At - Clusters],","),ALL(completed),completed[User Id] = user_id, completed[Month] = month_number)
        RETURN completed_string
        the difference is that since a calculated column has a built in row context you no longer need to use "max" to get the user_id and month_number but can just refer to them directly