Forum Discussion

Foguete's avatar
Foguete
Helper I
3 years ago
Solved

Addcolumn, different cases, summarize

Hello,

 

I need help as I am trying to build a table with a case I never face untill now.

I currently have a table with different line that I want to summarize.

For example:

 

datetaskcenterqty
01/01/20231a2
01/01/20232a3
02/01/20232a4
02/01/20232b5
02/01/20231a1
03/03/20231b2
03/03/20232a3
03/03/20231b4
03/03/20232a5

 

 

I want to SUMMARIZE by date, task, SUM(qty) BUT in the new table , I want to add a variable to "center", let's say C, which would be center A and B together.

 

So on the result would looks like this:

date

centertaskqty
01/01/2023a12
01/01/2023a23
01/01/2023c12
01/01/2023c23
02/01/2023a24
02/01/2023b25
02/01/2023a11
02/01/2023c29
02/01/2023c11
03/03/2023b16
03/03/2023a28
03/03/2023c16
03/03/2023c28

 

Any help regarding a function or anything I could use ?

 

Kind regards

  • hi Foguete 

    try to create a calculated table like:

    Table = 
    VAR _table= 
    ADDCOLUMNS(
        SUMMARIZE(
            TableName,
            TableName[Date],
            TableName[task]
        ),
        "center", "c",
        "Qty", CALCULATE(SUM(TableName[Qty]))
    )
    RETURN
    UNION(TableName, _table)

     

    verified and worked like this:

     

6 Replies

  • hi Foguete 

    try to create a calculated table like:

    Table = 
    VAR _table= 
    ADDCOLUMNS(
        SUMMARIZE(
            TableName,
            TableName[Date],
            TableName[task]
        ),
        "center", "c",
        "Qty", CALCULATE(SUM(TableName[Qty]))
    )
    RETURN
    UNION(TableName, _table)

     

    verified and worked like this:

     

    • FreemanZ's avatar
      FreemanZ
      Super User

      hi Foguete 

      if you mind the column ordering, try this:

      Table = 
      VAR _table=
      ADDCOLUMNS(
          SUMMARIZE(
              TableName,
              TableName[Date],
              TableName[task]
          ),
          "center", "c",
          "Qty", CALCULATE(SUM(TableName[Qty]))
      )
      VAR _table2= UNION(TableName, _table)
      RETURN
      SELECTCOLUMNS(
          _table2, 
          "date", TableName[date],
          "center", TableName[center],
          "task", TableName[task],
          "qty", TableName[qty]
      )

       

       

    • Foguete's avatar
      Foguete
      Helper I

      Thank you FreemanZ , however I have been simplifying "TableName" and in reality it has more column. So on, UNION is throwing the error "it must have the same number of columns".

       

      How can I get through that ?

      • FreemanZ's avatar
        FreemanZ
        Super User

        hi Foguete 

        i am afraid there might be no easy workaround. How many column do you have?