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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors