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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
kassymov_su
Frequent Visitor

Add subtotal Rows

Hi All,

 

I have a data with more than 2k activities in and with a column [Code for Area]. I need to group them by [Code for Area] and add a subtotal rows at the beginning of each group with Gruop Name. For example add subtotal row for code Civil-A1 and name it as "Civil works at area A1".  If i use add.rows then i Need to incert exact line but sometime we add a rows and extend the table so it won't work. What is the best practis to do that. Also when creating a subtotal row is there a way to sum up the volues of the gruop, I need rows before each group with gourp name and sum of volues (please see the example image below). The source table is very big and complex to make it manually

 

Снимок.PNG

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

NewStep=Table.Combine(Table.Group(PreviousStepName,"Code for Area",{"n",each #table(Table.ColumnNames(_),{{Text.Replace([Code for Area]{0},"-"," Works at Area "),null,List.Sum([Volumes])}})&_)})[n])

View solution in original post

5 REPLIES 5
v-eqin-msft
Community Support
Community Support

Hi @kassymov_su ,

 

Could you tell me if @wdx223_Daniel 's suggestion helps you ? If it is, kindly Accept it as the solution. More people will benefit from it.

 

Best Regards,
Eyelyn Qin

v-eqin-msft
Community Support
Community Support

Hi @kassymov_su ,

 

Actually in Power BI Desktop or Power Query,  there is no direct way like a button to add a column to add rows to table .

Usually we will Transpose the table -->Add columns --> Transpose again to indirectly add rows, or use M function——  Table.InsertRows()  which is not easy.

 

So I think the method provided by @wdx223_Daniel to add columns and show them in Matrix visual is the most efficient.

 

Best Regards,
Eyelyn Qin

wdx223_Daniel
Super User
Super User

NewStep=Table.Combine(Table.Group(PreviousStepName,"Code for Area",{"n",each #table(Table.ColumnNames(_),{{Text.Replace([Code for Area]{0},"-"," Works at Area "),null,List.Sum([Volumes])}})&_)})[n])

PijushRoy
Super User
Super User

Hi,

Create Conditional Column in Power Query (find steps)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY5BD4IwDIX/yrIzJkBAwtEQNJ71RjiUOc1i15ltEP33FuFi9Na+973Xdp1szGRws8tkItunggmiccRLlqayT778kzMoNA1Ad0uaIkv5SrWoVfROwYo2MKB+jIiGbiJ6oHB13mrPVlFu/0YOCHRhnMeyyD/IkUL0o138s+aAs0LN1cIt3azXVfUL743XYofgrQivELWdD9f8a/8G", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Code for Area" = _t, Activities = _t, Volumes = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Code for Area", type text}, {"Activities", type text}, {"Volumes", Int64.Type}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Group/Category", each if [Code for Area] = "Civil-A1" then "Civil Work at Area 1" else if [Code for Area] = "Electrocal-A1" then "Electrical Work at Area 1" else if [Code for Area] = "Instrum-A1" then "Instrument Work at Area 1" else null)
in
#"Added Conditional Column"

Or create Calculated Column in DAX

Group/Category = SWITCH(TRUE(),
Data[Code for Area]="Civil-A1","Civil Work at Area 1",
Data[Code for Area]="Electrocal-A1","Electrocal Work at Area 1",
Data[Code for Area]="Instrum-A1","Instrument Work at Area 1")
Create Matrix table in Power bi
PBI1.PNGpbi2.PNG
If any question, please LET ME know
If solve, mark this answer as SOLUTION
If helps you, LIKE this comment/Kudos.

Thanks

Thanks for the answer Roy,

 

But your solution in query is just to add a column. What I need is to add a row before each group

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.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

Top Solution Authors
Top Kudoed Authors