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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
royces99
Frequent Visitor

Add columns based off today's date and previous 3 months

I'm trying to add columns to a table with the column names being today's date and the previous 3 months (last day of month).  The code below is free of syntax errors but the last row of code shown generates the error message "Expression.Error: 2 arguments were passed to a function which expects between 3 and 4.  Details: Pattern= Arguments=[List]" and I don't know how to resolve it - what are the other 1 or 2 arguments that I need?  Can anybody help?

 

// STEP 1: Read the initial data
Source = database,

// Get today's date
today = DateTime.Date(DateTime.LocalNow()),

// Calculate the list of date column names
numColumns = 3,
column_names = List.Generate(
() => [i = 0, prevMonthEnd = today],
each [i] < numColumns,
each [i = [i] + 1, prevMonthEnd = Date.From(Date.EndOfMonth(Date.From(Date.AddMonths([prevMonthEnd], -1))))],
each if [i] = 1 then Text.From([prevMonthEnd], "dd-MM-yyyy") else Text.From([prevMonthEnd], "dd-MM-yyyy")
),

// Create a list of columns to add
columnsToAdd = List.Transform(column_names, each [Name = _ & " Column", Type = Int64.Type]),

// Add the columns
databaseWithColumns = Table.AddColumn(Source, columnsToAdd),

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

@royces99 replace last 2 steps with the following

databaseWithColumns = 
   List.Accumulate(
      column_names, 
      Source, 
      (s, c) => Table.AddColumn(s, c & " Column", each null, Int64.Type)
   )

View solution in original post

2 REPLIES 2
wdx223_Daniel
Super User
Super User

databaseWithColumns = Table.SelectColumns(Source,Table.ColumnNames(Source)&List.Transform({1..numColumns},each Date.ToText(Date.EndOfMonth(Date.AddMonths(today,_-1)),"dd-MM-yyyy")),2)

AlienSx
Super User
Super User

@royces99 replace last 2 steps with the following

databaseWithColumns = 
   List.Accumulate(
      column_names, 
      Source, 
      (s, c) => Table.AddColumn(s, c & " Column", each null, Int64.Type)
   )

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors