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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JusticeBaird
Frequent Visitor

DAX - Need next row value

Hello - 

 

I am attempting to create a new column utilizing DAX (or taking advice on how to accomplish the following).  I have a dataset that sometimes includes 'Beginning Balance' for [Date] and Null for [Account].  I am trying to replace the Null with the next rows value (within the same column).  Please reference the attached picture for current data set on the left and my future goal on the right. 

 

Thank you,

Justice

 

JusticeBaird_0-1635994874407.png

 

1 ACCEPTED SOLUTION

@JusticeBaird  this is not an analysis level task, rather it is a data level task which can be resolved by using PQ in the following way

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckpNV3BKzFHSUYIgQwMDA6VYnWglIwMjQ10DIDIBijol5mUDKV2gLJCyhCpB12uKotcQpB0o6qgfANJqCtZqAqJiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Account = _t, Amount = _t, Balance = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"Account", type text}, {"Amount", Int64.Type}, {"Balance", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "newAccount", each let x = #"Added Index"[Account],
    y = #"Added Index"[Date],
    z = if [Date]="Beg Bal" then x{[Index]+1} else [Account]

    in z),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

 

smpa01_0-1636038674380.png

 

 

 

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

7 REPLIES 7
JusticeBaird
Frequent Visitor

Sample data is stated below @BeaBF . Please note that my only goal is to bring in the applicable account name for for the blank 'Beginning Balance' rows.  Please let me know if you have any further questions. 

 

Date         | Account     | Amount     | Balance 

Beg Bal.   |                    |                   | 1000

1/4/2021 | Bank           |  -100          | 900

 

Beg Bal.  |                     |                   | 5000

1/11/21  | A/P              |     -500       | 4500   

@JusticeBaird  this is not an analysis level task, rather it is a data level task which can be resolved by using PQ in the following way

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckpNV3BKzFHSUYIgQwMDA6VYnWglIwMjQ10DIDIBijol5mUDKV2gLJCyhCpB12uKotcQpB0o6qgfANJqCtZqAqJiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Account = _t, Amount = _t, Balance = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"Account", type text}, {"Amount", Int64.Type}, {"Balance", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "newAccount", each let x = #"Added Index"[Account],
    y = #"Added Index"[Date],
    z = if [Date]="Beg Bal" then x{[Index]+1} else [Account]

    in z),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

 

smpa01_0-1636038674380.png

 

 

 

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

I copy/pasted you logic and came up with the same results as you, now which part of the logic to I need to update to return the full table?

 

Thank you,

 

@JusticeBaird try running the code from #"Added Index" onwards in your original dataset. It should not create any issue.

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

I am still unable to get it to return the information I need.. Would it help if I sent the current Source Logic and see what parts I should update to incorporate your logic?

 

let
Source = Excel.Workbook(File.Contents("C:\Users\justi\Desktop\TG\Power BI\Quickbooks\General Ledger.xlsx"), null, false),
#"General Ledger_sheet" = Source{[Item="General Ledger",Kind="Sheet"]}[Data],
FilterNullAndWhitespace = each List.Select(_, each _ <> null and (not (_ is text) or Text.Trim(_) <> "")),
#"Removed Bottom Rows" = Table.RemoveLastN(#"General Ledger_sheet", each try List.IsEmpty(List.Skip(FilterNullAndWhitespace(Record.FieldValues(_)), 1)) otherwise false),
#"Removed Top Rows" = Table.Skip(#"Removed Bottom Rows", each try List.IsEmpty(List.Skip(FilterNullAndWhitespace(Record.FieldValues(_)), 1)) otherwise false),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Column1", type text}, {"Date", type text}, {"Account", type text}, {"Transaction Type", type text}, {"Num", type any}, {"Memo/Description", type text}, {"Split", type text}, {"Amount", type number}, {"Balance", type number}, {"Name", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Weird Name"}}),
#"Added Index" = Table.AddIndexColumn(#"Renamed Columns", "Index", 1, 1, Int64.Type),
#"Sorted Rows" = Table.Sort(#"Added Index",{{"Index", Order.Ascending}})
in
#"Sorted Rows"

BeaBF
Impactful Individual
Impactful Individual

@JusticeBaird 

yes, but if the lines were not in this order, you need a rule to assign the occunt bank rather than loan. what is this rule?

BeaBF
Impactful Individual
Impactful Individual

@JusticeBaird  Could you paste the data on which to calculate the column?

 

Thx,

B.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.