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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Foguete
Helper I
Helper I

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

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

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_0-1674573275619.png

 

View solution in original post

6 REPLIES 6
FreemanZ
Super User
Super User

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_0-1674573275619.png

 

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 ?

hi @Foguete 

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

Hi @FreemanZ,

Thanks for the DAX, a slight modification and I have found the solution.

 

Here in red, it is in case someone would get there:

 

UNION(
    SELECTCOLUMNS(
        TableName,
            "date", TableName[date],
            "task", TableName[task],
            "center", TableName[center],
            "qty", TableName[qty]
    ),
    _table)

Brilliant! Great idea!

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]
)

 

FreemanZ_1-1674573709617.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.