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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
VictorR
Frequent Visitor

How to create a new column that is a sum of one column and grouped by another column

Hi,

 

So I have data in a table I labelled VesselLoadDischarge that breaks down the number of containers by Discharge and Load per Vessel as shown in the image below:

 

2018-06-22_10-13-50.jpg

 

 

 

 

 

 

 

 

 I am trying to add a new column (say called SummedUnitCount) that sums the "UnitCount" column by VesselVisitCode column; ie: the first two rows would each have 642 (the sum of each row from the UnitCount column with VesselVisitCode = SCB3129 which is 377 +265), the next two rows would have 533 each (the sum of each row from the UnitCount column with VesselVisitCode = ALO3372 which is 304 + 229) and so on.

 

Note: It is not guaranteed that every entry in VesselVisitCode occurs twice, however, it is guaranteed that there can't be more than two entries per VesselVisitCode

 

Appreciate your assistance.

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

HI @VictorR

 

This calculated column gets pretty close.  I have attached a pbix file

 

SummedUnitCount = 
    SUMX(
        FILTER(
            'Table1',
            'Table1'[VesselVisitCode] = EARLIER('Table1'[VesselVisitCode])
            ),
      'Table1'[UnitCount])

image.png

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

2 REPLIES 2
Phil_Seamark
Employee
Employee

HI @VictorR

 

This calculated column gets pretty close.  I have attached a pbix file

 

SummedUnitCount = 
    SUMX(
        FILTER(
            'Table1',
            'Table1'[VesselVisitCode] = EARLIER('Table1'[VesselVisitCode])
            ),
      'Table1'[UnitCount])

image.png

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thank you Phil! That worked exactly as I was hoping and expecting it to.

 

I appreciate your time to assist me here and thank you for the sample .pbix file as well.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.