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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
M_Tugz
New Member

Transforming data

Good day all,

 

I'm pretty new to Power BI, never coded in my life and desperately need your expertise and help. I would like to clean up and create a single row for my data. However, as you will see in the extract below, my reports has has inconsistent outputs where sometimes a transactions has 3 rows showing an account and an additional reference and sometimes two rows with just one refeence. I'm not sure if there's a single transformation in PowerBI i can use (I'm not yet on DAX!!)

 

Post dateReferenceNarrativeValue Date DebitCreditClosing Balance
21-Jul-17FT172P6MNKPayment21-Jul-17  1.021.02
  TR14322     
   AC - 45221     
21-Jul-17FT172S00XWAgent Transfer21-Jul-17  1.022.04
  TR54322     
1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

At the same time I was preparing a similar solution along with a video for clarification.

I made some assumptions (about table keys and how the result should look like).

 

The code:

 

let
    Source = Table1,
    #"Filled Down" = Table.FillDown(Source,{"Post date", "Reference"}),
    Narratives = Table.Group(#"Filled Down", {"Post date", "Reference"}, {{"Narrative", each Text.Combine([Narrative], "#(lf)"), type text}}),
    Custom1 = Source,
    #"Removed Columns" = Table.RemoveColumns(Custom1,{"Narrative"}),
    #"Removed Blank Rows" = Table.SelectRows(#"Removed Columns", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Merged Queries" = Table.NestedJoin(#"Removed Blank Rows",{"Post date", "Reference"},Narratives,{"Post date", "Reference"},"Narrative",JoinKind.LeftOuter),
    #"Expanded Narrative" = Table.ExpandTableColumn(#"Merged Queries", "Narrative", {"Narrative"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Narrative",{"Post date", "Reference", "Narrative", "Value Date", "Debit", "Credit", "Closing Balance"})
in
    #"Reordered Columns"

 

The video:

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
fhill
Resident Rockstar
Resident Rockstar

There is a 'Fill Down' option in Query Editor to fill blank spaces with values from previous rows.  This could be useful to assign data to blank rows, but be careful with Fill when it comes to the Credits / Debits you have listed not to duplicate / triplicate this data erronoursly.  

 

Consider something along these lines.... 1. Duplicate your Table and only keep the neeeded columns associated with Credit / Debit columns and remove all the other rows with blanks.  (You'll probably want to un-pivot those two also to bring them together eventually....?)

2. Once youv'e stripped out datat that would become false when Filled Donw, then Fill Down with the remaining columns.  

3. Start buliding relationshpis to link your data back together.

 

If you post a few more rows of data, we can better show this process in examples.  FOrrest




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




MarcelBeug
Community Champion
Community Champion

At the same time I was preparing a similar solution along with a video for clarification.

I made some assumptions (about table keys and how the result should look like).

 

The code:

 

let
    Source = Table1,
    #"Filled Down" = Table.FillDown(Source,{"Post date", "Reference"}),
    Narratives = Table.Group(#"Filled Down", {"Post date", "Reference"}, {{"Narrative", each Text.Combine([Narrative], "#(lf)"), type text}}),
    Custom1 = Source,
    #"Removed Columns" = Table.RemoveColumns(Custom1,{"Narrative"}),
    #"Removed Blank Rows" = Table.SelectRows(#"Removed Columns", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Merged Queries" = Table.NestedJoin(#"Removed Blank Rows",{"Post date", "Reference"},Narratives,{"Post date", "Reference"},"Narrative",JoinKind.LeftOuter),
    #"Expanded Narrative" = Table.ExpandTableColumn(#"Merged Queries", "Narrative", {"Narrative"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Narrative",{"Post date", "Reference", "Narrative", "Value Date", "Debit", "Credit", "Closing Balance"})
in
    #"Reordered Columns"

 

The video:

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.