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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Make costum a calculated column with formula (last column - sum "Volume Third Party" : last column)

Hi! I have a power query which gets data from a table. These table containts specific columns which are called "Volume Third Party". Table is dynamic which means that the number of columns including columns which are called "Volume Third Party"  can increase or decrease. I want to add costum column with the following formula (last column - sum range between "Volume Third Party" to last column). Between these range there are columns with the name "Volume Third Party_*different number*". I have attached screenshot to make it more clear:

Capture.PNG

 

After adding costum column it should add filter to last column and to column with custom function which would remove rows with 0 & blank values. Is it possible to do? 

 

Current code:

 

let
    Source = Excel.CurrentWorkbook(){[Name="SAPCrosstab1"]}[Content],
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([#""] <> "R001" and [#""] <> "R003") and ([_6] <> "#"))
in
    #"Filtered Rows"

 

 

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Without an example of your data and results, it's hard to tell exactly what you want, but this custom column formula should get you started.

 

 

 

 

   [Last Column] -
        List.Sum(
            Record.FieldValues(
                Record.SelectFields(_,
                    List.Select(
                        List.RemoveLastN(Record.FieldNames(_),1), 
                        each Text.StartsWith(_,"Volume Third Party")))))

 

 

 

 

In the formula above, know that:

  • The underscore "_" argument in Record.SelectFields will return the entire row as a record
  • #"Changed Type" is the previous step.  Alter that if necessary
  • List.RemoveLastN(... removes the Last column name from the list of Field names
  • List.Select returns a list of all the remaining Field names that start with "Volume Third Part"
  • Record.Select returns just those fields from the entire record (row)
  • And finally we Sum the values of those particular records to subtract from the value in the Last Column

 

Adding a filter, or changing which columns to sum/subtract, should be easy for you to modify.

 

ronrsnfld_0-1634491595614.png

 

 

View solution in original post

2 REPLIES 2
ronrsnfld
Super User
Super User

Without an example of your data and results, it's hard to tell exactly what you want, but this custom column formula should get you started.

 

 

 

 

   [Last Column] -
        List.Sum(
            Record.FieldValues(
                Record.SelectFields(_,
                    List.Select(
                        List.RemoveLastN(Record.FieldNames(_),1), 
                        each Text.StartsWith(_,"Volume Third Party")))))

 

 

 

 

In the formula above, know that:

  • The underscore "_" argument in Record.SelectFields will return the entire row as a record
  • #"Changed Type" is the previous step.  Alter that if necessary
  • List.RemoveLastN(... removes the Last column name from the list of Field names
  • List.Select returns a list of all the remaining Field names that start with "Volume Third Part"
  • Record.Select returns just those fields from the entire record (row)
  • And finally we Sum the values of those particular records to subtract from the value in the Last Column

 

Adding a filter, or changing which columns to sum/subtract, should be easy for you to modify.

 

ronrsnfld_0-1634491595614.png

 

 

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. Paste the data into a table in your post or use one of the file services. Please show the expected outcome.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.