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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
xpisoverated
Regular 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 is the filename, e.g. June.csv, July.csv, etc.

 

The table is formatted something like this

ID, Name, Score, Filename

 

So in most cases each ID will appear 3 times, once for each of the csv files, e.g

1,A,12,May.csv

1,A,15,June.csv

1,A,15,July.csv

 

The scores may change from file to file.

 

For each row of data in the file i would like to create a column that shows the score value for a particular month, i.e. adding a column something like

ID, Name, Score, Filename,May,June,July

 

So the data in the table would end up as

1,A,12,May.csv,12,15,15

1,A,15,June.csv,12,15,15

1,A,15,July.csv,12,15,15

 

How would i syntax the column dax to do this ?

4 REPLIES 4
jgeddes
Super User
Super 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




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Arul
Super User
Super User

In the power query,

Click Month column and Pivot under transform using Score as Values.
Arul_0-1784815363631.png
 
Output:
Arul_1-1784815392410.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


MasonMA
Super User
Super User

Since the data already contains the filename, you can do this in Power Query instead by Pivot Column.

Use Score as the Values column. (Under Advanced options, choose Don't Aggregate)

If you still need the original row structure, you can merge this pivoted table back onto the original table. This is generally simpler to maintain than creating one DAX calculated column per month.

Thanks Pivot works perfectly, one question, if i pivot on the date, so in effect my table visual is

Name,Date1,Date2,Date3

 

Is there an easy was to add a column or measure after date3 that shows if the value in date 1 and 2 has increased, decreased or stayed the same ?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.