Forum Discussion
xpisoverated
27 days agoRegular Visitor
Getting a value into a column from the same table
I'm sure i'm missing something obvious, but here goes I have a sharepoint folder with 3 csv files in it, i bring them all into a single table via the folder import. One of the columns in the table ...
- 15 days ago
Hi xpisoverated
Yes, you can definitely add logic to compare values across pivoted dates. Since your table visual is showing Name, Date1, Date2, Date3, you want a measure that checks the difference between Date1 and Date2, then returns a text label like Increased, Decreased, or No Change.
jgeddes
27 days agoSuper User
MasonMA has provided the easiest solution.
If you want to maintain your original table format and you do not want to use table joins, here is a solution. It is likely overkill for your solution but it explores table grouping, nested lists, dynamic column renaming, and dynamic column type setting. Cheers.
let
//example data
Source =
Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WMlTSUXIEYkMjIOGbWKmXXFymFKuDJGEKJLxK81JxyeQg9BjBZEzQDINLmKNoiQUA",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t, Score = _t, Filename = _t]
),
//type setting of initial data
initial_type_set =
Table.TransformColumnTypes(
Source,
{
{"ID", Int64.Type}, {"Name", type text}, {"Score", Int64.Type}, {"Filename", type text}
}
),
//get distinct list of filenames
fileList =
List.Distinct(initial_type_set[Filename]),
//create a type setting list that sets month columns to Int64 and the filename column to text
typeList =
List.Combine(
{
List.Zip(
{
List.Transform(fileList, each Text.BeforeDelimiter(_, ".csv")),
List.Repeat({Int64.Type}, List.Count(fileList))
}
),
{{"Filename", Text.Type}}
}
),
//group table by ID and Name using all rows as the aggregate
group_rows =
Table.Group(
initial_type_set,
{"ID", "Name"},
{
{"AllRows", each _, type table [ID=nullable number, Name=nullable text, Score=nullable number, Filename=nullable text]}
}
),
//add a column to the nested table that contains list of distinct filenames for the ID Name table
add_filenames =
Table.TransformColumns(
group_rows,
{
{"AllRows", each let names = [Filename] in Table.AddColumn(Table.Pivot(_, List.Distinct(_[Filename]), "Filename", "Score"), "Filename", each names, type list), type table}
}
),
//expand the nested table, dropping the '.csv' from the filename columns
expand_nested =
Table.ExpandTableColumn(
add_filenames,
"AllRows",
List.Combine({fileList, {"Filename"}}),
List.Combine({List.Transform(fileList, each Text.BeforeDelimiter(_, ".csv")), {"Filename"}})
),
//expand the filename list column to new rows
expand_filenames =
Table.ExpandListColumn(
expand_nested,
"Filename"
),
//set the column data types
final_type_set =
Table.TransformColumnTypes(
expand_filenames,
typeList
)
in
final_type_set