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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
julien-rivley
Helper I
Helper I

ADDCOLUMN subtotal in DAX

Hello,

 

Sorry if this was already replied in a previous post but I could not find anything... While creating a dax table, I can't find any way to add the column "Subtotal" which is the sum of the value for the same Dim1, would anyone has an idea?

 

Thanks,

Julien


Dim1Dim2ValueSubtotal
A#11060
A#22060
A#33060
B#440150
B#550150
B#660150


My code looks like this:

VAR T_1=
ADDCOLUMNS(
   CROSSJOIN(Dim1,Dim2)
   ,"Value"
   ,[Measure]
)

VAR T_2=
ADDCOLUMNS(
   T_1
   ,"Subtotal"
   ,SUMX(
      FILTER(
         T_1
         ,All(Dim1)
      )
      ,[Value]
   )
)
1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @julien-rivley 

Assuming T_1 is correct:

VAR T_2 =
ADDCOLUMNS (
    T_1,
    "Subtotal", SUMX ( FILTER ( T_1, [Dim1] = EARLIER ( [Dim1] ) ), [Value] )
)

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

View solution in original post

2 REPLIES 2
julien-rivley
Helper I
Helper I

Thanks a lot! I got lost with the use of "Filter" 🙂

AlB
Super User
Super User

Hi @julien-rivley 

Assuming T_1 is correct:

VAR T_2 =
ADDCOLUMNS (
    T_1,
    "Subtotal", SUMX ( FILTER ( T_1, [Dim1] = EARLIER ( [Dim1] ) ), [Value] )
)

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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