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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Add index based on a column

Hi 🙂

 

I need to create a table based on two columns on other table. 

Example: 

I have an activity with the duration in days 

Activityduration days
12
25
3

1

 

I want to expand the days to repeat the activities

ActivityDay
11
12
23
24
25
26
27
38
1 ACCEPTED SOLUTION
AntrikshSharma
Super User
Super User

@Anonymous 

let
    Source = Excel.CurrentWorkbook(){[ Name = "Table1" ]}[Content],
    ChangedType = Table.TransformColumnTypes (
        Source,
        { { "Activity Duration", Int64.Type }, { "Days", Int64.Type } }
    ),
    RepeatDuration = Table.AddColumn (
        ChangedType,
        "Custom",
        each Table.FromColumns (
            { List.Repeat ( { [Activity Duration] }, [Days] ) },
            type table [ ActivityDuraton = Int64.Type ]
        ),
        type table [ ActivityDuraton = Int64.Type ]
    ),
    RemovedColumns = Table.RemoveColumns ( RepeatDuration, { "Activity Duration", "Days" } ),
    ExpandedCustom = Table.ExpandTableColumn (
        RemovedColumns,
        "Custom",
        { "ActivityDuraton" },
        { "ActivityDuraton" }
    ),
    AddedIndex = Table.AddIndexColumn ( ExpandedCustom, "Index", 1, 1, Int64.Type )
in
    AddedIndex

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you AntrikshSharma!

 

I needed to do some small adjustments, and here we go! It works! 😄

 

Regards,

Vesta 

AntrikshSharma
Super User
Super User

@Anonymous 

let
    Source = Excel.CurrentWorkbook(){[ Name = "Table1" ]}[Content],
    ChangedType = Table.TransformColumnTypes (
        Source,
        { { "Activity Duration", Int64.Type }, { "Days", Int64.Type } }
    ),
    RepeatDuration = Table.AddColumn (
        ChangedType,
        "Custom",
        each Table.FromColumns (
            { List.Repeat ( { [Activity Duration] }, [Days] ) },
            type table [ ActivityDuraton = Int64.Type ]
        ),
        type table [ ActivityDuraton = Int64.Type ]
    ),
    RemovedColumns = Table.RemoveColumns ( RepeatDuration, { "Activity Duration", "Days" } ),
    ExpandedCustom = Table.ExpandTableColumn (
        RemovedColumns,
        "Custom",
        { "ActivityDuraton" },
        { "ActivityDuraton" }
    ),
    AddedIndex = Table.AddIndexColumn ( ExpandedCustom, "Index", 1, 1, Int64.Type )
in
    AddedIndex

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.