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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
philipsr1
Regular Visitor

Need help on adding new rows from colums

Need some advice .I have a table with a row contraining three receive dates and three receive amounts. I am looking for a way to convert them into three rows  as shown below

 

Original

RECACCTRECDATE1RECAMT1RECDATE2RECAMT1RECDATE3RECAMT1
300042019111333009.0520200417-41860.252020041741860.25
300052020041723993.71000000000000000000

 

Desired output

 

RECACCT  RECDATE              RECAMT

30004        20191113               33009.05

30004        20200417             -41860.25

30004        20200417              41860.25

30005        20200417              23993.71

 

Any help would be appriciated

 

Thanks

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RECACCT", type text}, {"RECDATE1", Int64.Type}, {"RECAMT1", type number}, {"RECDATE2", Int64.Type}, {"RECAMT12", type number}, {"RECDATE3", Int64.Type}, {"RECAMT13", type number}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"RECACCT"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Character Transition",{"Attribute.2"}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Removed Columns", {{"RECACCT", type text}}, "en-IN"),{"RECACCT", "Attribute.1"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged"),
    #"Added Index" = Table.AddIndexColumn(#"Merged Columns", "Index", 1, 1),
    Partition = Table.Group(#"Added Index", {"Merged"}, {{"Partition", each Table.AddIndexColumn(_, "Index1",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Value", "Index", "Index1"}, {"Value", "Index", "Index1"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Partition",{{"Index", Order.Ascending}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows",{"Index"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns1", "Merged", Splitter.SplitTextByEachDelimiter({","}, QuoteStyle.Csv, false), {"Merged.1", "Merged.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter", List.Distinct(#"Split Column by Delimiter"[Merged.2]), "Merged.2", "Value"),
    #"Removed Columns2" = Table.RemoveColumns(#"Pivoted Column",{"Index1"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Removed Columns2",{{"RECAMT", type number}})
in
    #"Changed Type2"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RECACCT", type text}, {"RECDATE1", Int64.Type}, {"RECAMT1", type number}, {"RECDATE2", Int64.Type}, {"RECAMT12", type number}, {"RECDATE3", Int64.Type}, {"RECAMT13", type number}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"RECACCT"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Character Transition",{"Attribute.2"}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Removed Columns", {{"RECACCT", type text}}, "en-IN"),{"RECACCT", "Attribute.1"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged"),
    #"Added Index" = Table.AddIndexColumn(#"Merged Columns", "Index", 1, 1),
    Partition = Table.Group(#"Added Index", {"Merged"}, {{"Partition", each Table.AddIndexColumn(_, "Index1",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Value", "Index", "Index1"}, {"Value", "Index", "Index1"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Partition",{{"Index", Order.Ascending}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows",{"Index"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns1", "Merged", Splitter.SplitTextByEachDelimiter({","}, QuoteStyle.Csv, false), {"Merged.1", "Merged.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter", List.Distinct(#"Split Column by Delimiter"[Merged.2]), "Merged.2", "Value"),
    #"Removed Columns2" = Table.RemoveColumns(#"Pivoted Column",{"Index1"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Removed Columns2",{{"RECAMT", type number}})
in
    #"Changed Type2"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@philipsr1 you need to unpivot your table

 

- click transform data

- select RECACCT column 

- right-click and select unpivot other columns

 

you will get two new columns, attribute, and value

 

- rename attribute to RecDate and value to Amount

 

and now you can visualize the data the way you want. and it is best practice from the modeling perspective.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Unfortunately unpivot does not work in my scenario. Unpivot as I understand works for example , when you have data of sales for mutiple Years. So the heading like 2015,2016,2017, 2018 as column headings with sale amounts of each of them under it. So when you unpivot it converts years(the heading) as attributes and sales as values. My case is different. I have
RECDATE1,RECAMT1,RECDATE2,RECAMT2,RECDATE3,RECAMT3 as headings and corresponding values underneath it. and I am looking for a way to create two colums with the value of RECDATE in one column and the corresponding RECAMT value on the other.I made a typo on my heading which might have caused the confusion.

I am entering the input and the desired output

Original
RECACCT           RECDATE1            RECAMT1            RECDATE2     RECAMT2         RECDATE3     RECAMT3
30004                20191113             33009.05             20200417     -41860.25        20200417      41860.25
30005                20200417             23993.71             00000000      0                       00000000      0

 

Desired output

 

RECACCT      RECDATE      RECAMT

30004           20191113     33009.05

30004           20200417    -41860.25

30004           20200417     41860.25

30005           20200417     23993.71

 

Thanks

Hi @philipsr1 ,

 

Check this file as an example:  Download PBIX 

 

directquery_sqlserverdb.png

 

Ricardo



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.