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
Jmiller
Regular Visitor

Combine rows with offset. A2 + B1

Trying to find away to combine two rows but the combination needs to have a offset as shown below. 

 

 

Example.PNG

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

Can be done in M @Jmiller 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtJR8klNK1GK1QGzgzLTMyCc4ILUvJTMvHSgIFGSRJgSCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Spending = _t, #"Non-Spending" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Spending", type text}, {"Non-Spending", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1),
    #"Filtered Rows" = Table.SelectRows(#"Added Index", each ([Spending] = "Spending")),
    #"Inserted Subtraction" = Table.AddColumn(#"Filtered Rows", "Subtraction", each [Index] - 1, type number),
    #"Merged Queries" = Table.NestedJoin(#"Inserted Subtraction",{"Subtraction"},#"Added Index",{"Index"},"Inserted Subtraction",JoinKind.LeftOuter),
    #"Expanded Inserted Subtraction" = Table.ExpandTableColumn(#"Merged Queries", "Inserted Subtraction", {"Non-Spending"}, {"Non-Spending.1"}),
    #"Inserted Merged Column" = Table.AddColumn(#"Expanded Inserted Subtraction", "Merged", each Text.Combine({[Spending], [#"Non-Spending.1"]}, "+"), type text),
    #"Removed Other Columns" = Table.SelectColumns(#"Inserted Merged Column",{"Index", "Merged"}),
    #"Merged Queries1" = Table.NestedJoin(#"Added Index",{"Index"},#"Removed Other Columns",{"Index"},"Removed Other Columns",JoinKind.LeftOuter),
    #"Expanded Removed Other Columns" = Table.ExpandTableColumn(#"Merged Queries1", "Removed Other Columns", {"Merged"}, {"Merged"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Removed Other Columns",{{"Index", Order.Ascending}})
in
    #"Sorted Rows"

Capture.JPG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
smpa01
Super User
Super User

Can be done in M @Jmiller 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtJR8klNK1GK1QGzgzLTMyCc4ILUvJTMvHSgIFGSRJgSCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Spending = _t, #"Non-Spending" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Spending", type text}, {"Non-Spending", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1),
    #"Filtered Rows" = Table.SelectRows(#"Added Index", each ([Spending] = "Spending")),
    #"Inserted Subtraction" = Table.AddColumn(#"Filtered Rows", "Subtraction", each [Index] - 1, type number),
    #"Merged Queries" = Table.NestedJoin(#"Inserted Subtraction",{"Subtraction"},#"Added Index",{"Index"},"Inserted Subtraction",JoinKind.LeftOuter),
    #"Expanded Inserted Subtraction" = Table.ExpandTableColumn(#"Merged Queries", "Inserted Subtraction", {"Non-Spending"}, {"Non-Spending.1"}),
    #"Inserted Merged Column" = Table.AddColumn(#"Expanded Inserted Subtraction", "Merged", each Text.Combine({[Spending], [#"Non-Spending.1"]}, "+"), type text),
    #"Removed Other Columns" = Table.SelectColumns(#"Inserted Merged Column",{"Index", "Merged"}),
    #"Merged Queries1" = Table.NestedJoin(#"Added Index",{"Index"},#"Removed Other Columns",{"Index"},"Removed Other Columns",JoinKind.LeftOuter),
    #"Expanded Removed Other Columns" = Table.ExpandTableColumn(#"Merged Queries1", "Removed Other Columns", {"Merged"}, {"Merged"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Removed Other Columns",{{"Index", Order.Ascending}})
in
    #"Sorted Rows"

Capture.JPG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Interesting. I will have to put some time into copying that over tonight. Not that advanced with PowerBI. 

Anonymous
Not applicable

You should be able to combine them with the below function:

 

Column = CONCATENATE(Sheet1[Speeding], CONCATENATE(", ", Sheet1[Vehicle.Count]))

That works if the data is in the same row but not when the row is offset. 

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.

Top Solution Authors