Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello,
I am trying to see if it's possible to increment a variable within an each function.
#"Table With EventKey" = Table.AddColumn(#"OriginalData", "EventKeyTable", each let
AllData = [Custom],
Counter = 0,
AddToCounter = () => Counter = Counter +1,
PrevRowComparison =
Table.AddColumn(AllData, "EventKey",
(x) =>
let
Val = if x[PrevEventNo] = x[EventNo] then null else AddToCounter()
in
Counter )
in PrevRowComparison)
How would I go about creating and implementing a function that will increase the Counter value and then I can retrieve the counter value to place into the row?
I would like the output to be something like the image show below.
| Index | EventNo | PrevEventNo | EventKey |
| 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 0 |
| 2 | 3 | 1 | 1 |
| 3 | 3 | 3 | 1 |
| 4 | 3 | 3 | 1 |
| 5 | 4 | 3 | 2 |
| 6 | 4 | 4 | 2 |
| 7 | 1 | 4 | 3 |
| 8 | 3 | 1 | 4 |
Solved! Go to Solution.
NewStep=Table.FromRecords(List.Accmulate(Table.ToRecords(PreviousStepName),{{},0},(x,y)=>let a=x{1}+Byte.From(y[EventNo]<>y[PrevEventNo]) in {x{0}&{y&[EventKey=a]},a}){0})
If anyone is interested, using @wdx223_Daniels solution. I did the following since I have nested tables.
#"Table With EventKey" = Table.AddColumn(#"OriginalData", "EventKeyTable", each let
AllData = [Custom],
NewStep=Table.FromRecords(List.Accumulate(Table.ToRecords(AllData),{{},0},(x,y)=>let
a=x{1}+Byte.From(y[EventNo]<>y[PrevEventNo]) in {x{0}&{y&[EventKey=a]},a}){0})
in NewStep)
NewStep=Table.FromRecords(List.Accmulate(Table.ToRecords(PreviousStepName),{{},0},(x,y)=>let a=x{1}+Byte.From(y[EventNo]<>y[PrevEventNo]) in {x{0}&{y&[EventKey=a]},a}){0})
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 7 | |
| 5 | |
| 5 |