Forum Discussion
Anonymous
3 years agoNot applicable
Replicating excel formula | precedent referencing
Hello community, Need help in replicating the following formula in DAX or in power query - In Excel we can easily use precedent referencing but in dax or power query I haven't found anything,...
- 3 years ago
let Source = your_source_table, data = List.Buffer(Source[Total engine hours]), max_count = List.Count(data), pulse = List.Generate( () => [i = 0, p = 0], (x) => x[i] < max_count, (x) => [i = x[i] + 1, p = if (data{i} >= data{x[i]}) then x[p] + data{i} - data{x[i]} else x[p]], (x) => x[p] ), out = Table.FromColumns(Table.ToColumns(Source) & {pulse}, Table.ColumnNames(Source) & {"Pulse"}) in out
AlienSx
3 years agoSuper User
Hi, Anonymous
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
data = List.Buffer(Source[Total engine hours]),
max_count = List.Count(data),
pulse =
List.Generate(
() => [i = 0, p = 0],
(x) => x[i] < max_count,
(x) => [i = x[i] + 1, p = if (data{i} >= data{x[i]}) then x[p] + data{i} - data{x[i]} else x[p]],
(x) => x[p]
),
out = Table.FromColumns({data, pulse}, {"Total engine hours", "Pulse"})
in
outAnonymous
3 years agoNot applicable
AlienSx, this sort of solves my issue, but my actual data comes from sql database which has this 'Total engine hours' with multiple other columns, which of the bits i would need to edit then?
- AlienSx3 years agoSuper User
let Source = your_source_table, data = List.Buffer(Source[Total engine hours]), max_count = List.Count(data), pulse = List.Generate( () => [i = 0, p = 0], (x) => x[i] < max_count, (x) => [i = x[i] + 1, p = if (data{i} >= data{x[i]}) then x[p] + data{i} - data{x[i]} else x[p]], (x) => x[p] ), out = Table.FromColumns(Table.ToColumns(Source) & {pulse}, Table.ColumnNames(Source) & {"Pulse"}) in out- Anonymous3 years agoNot applicable
I believe this will definitely help, thank you so much!
Do you know if there's a way we can achieve the same through DAX?
- AlienSx3 years agoSuper User
DAX - most likely yes but I am not a DAX guy (yet) 😎