Dynamics F&O Database Logs
Imagine you have a piece of text that looks like this:
field1 ÿþ old1 ÿþ new1 ÿþ field2 ÿþ old2 ÿþ new2 ÿþ field3 ÿþ old3 ÿþ new3 ÿþ field4 ÿþ old4 ÿþ ÿþ
What is ÿþ? Apparently it's a Windows interpetation of a byte-order mark. This is something that might come out of the database logs in Dynamics F&O. This is a representation of a table, where it should look like this:
| Field | Old | New |
|---|---|---|
| field1 | old1 | new1 |
| field2 | old2 | new2 |
| field3 | old3 | new3 |
| field4 | old4 |
How do we parse this out? Read on and find out.
Batching
We are assuming that the string is of a pattern where things come in threes. The strategy here is to batch the text into groups of three, and then from there, parse out the fields.
First, we split the text by the delimiter, and add an index, starting with 0.
addIndex = Table.AddIndexColumn(table, "Index", 0, 1, Int64.Type),
| Value | Index |
|---|---|
| field1 | 0 |
| old1 | 1 |
| new1 | 2 |
| field2 | 3 |
| old2 | 4 |
| new2 | 5 |
| field3 | 6 |
| old3 | 7 |
| new3 | 8 |
| field4 | 9 |
| old4 | 10 |
| 11 |
Then we would integer-divide all of the indices, by doing something like this:
batchIndex = Table.TransformColumns( addIndex, { { "Index", each Number.IntegerDivide(_, 3) } } )
| Value | Index |
|---|---|
| field1 | 0 |
| old1 | 0 |
| new1 | 0 |
| field2 | 1 |
| old2 | 1 |
| new2 | 1 |
| field3 | 2 |
| old3 | 2 |
| new3 | 2 |
| field4 | 3 |
| old4 | 3 |
| 3 |
Now we can visually see that they're in batches of three rows each. Now we can group them.
grouped = Table.Group(
batchIndex,
{"Index"},
{
{
"Group",
each [
Field = _{0}[Value]?,
Old = _{1}[Value]?,
New = _{2}[Value]?
],
type record
}
}
)