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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
unclejemima
Post Patron
Post Patron

Function expects a column name as argument number 4? Help :-)

I'm trying to use this code but getting the error "Fuction Expects ADDCOLUMNS expects a column name as argument number 4.""

 

DateTime = 
ADDCOLUMNS (
    CROSSJOIN (
        CALENDAR(MIN(Invoice[NvDate]),max(Invoice[NvDate])),
        UNION (
            ROW ( "Time", TIME ( 1, 0, 0 ) ),
            ROW ( "Time", TIME ( 2, 0, 0 ) ),
            ROW ( "Time", TIME ( 3, 0, 0 ) ),
            ROW ( "Time", TIME ( 4, 0, 0 ) ),
            ROW ( "Time", TIME ( 5, 0, 0 ) ),
            ROW ( "Time", TIME ( 6, 0, 0 ) ),
            ROW ( "Time", TIME ( 7, 0, 0 ) ),
            ROW ( "Time", TIME ( 9, 0, 0 ) ),
            ROW ( "Time", TIME ( 10, 0, 0 ) ),
            ROW ( "Time", TIME ( 11, 0, 0 ) ),
            ROW ( "Time", TIME ( 12, 0, 0 ) ),
            ROW ( "Time", TIME ( 13, 0, 0 ) ),
            ROW ( "Time", TIME ( 14, 0, 0 ) ),
            ROW ( "Time", TIME ( 15, 0, 0 ) ),
            ROW ( "Time", TIME ( 16, 0, 0 ) ),
            ROW ( "Time", TIME ( 17, 0, 0 ) ),
            ROW ( "Time", TIME ( 18, 0, 0 ) ),
            ROW ( "Time", TIME ( 19, 0, 0 ) ),
            ROW ( "Time", TIME ( 20, 0, 0 ) ),
            ROW ( "Time", TIME ( 21, 0, 0 ) ),
            ROW ( "Time", TIME ( 22, 0, 0 ) ),
            ROW ( "Time", TIME ( 23, 0, 0 ) ),
            ROW ( "Time", TIME ( 24, 0, 0 ) )
        )
    ),
    "DateTime", [Date] + [Time],)
1 ACCEPTED SOLUTION

Hi @unclejemima

 

Yes... AddColumn is a function which returns a Table......It cannot be used in Calculated Columns and Measures....Directly..

 

However you can use this code as a CALCULATED TABLE
So if you go to Modelling Tab>>New Table and paste this code...you will get an entirely new Table in your Model

 

 

 

View solution in original post

9 REPLIES 9
Zubair_Muhammad
Community Champion
Community Champion

@unclejemima

 

I see an unnecessary comma at the end of this code before the bracket close

Try removing it

, )

 

 

Sorry doing so now I get a "The expression refers to multiple columns.  Multiple columns cannot be converted to a scalar value 

Hi @unclejemima

 

This is a calculated table right???

 

I hope you are not using it as a MEASURE or Calculated Column

 

When I use it as a calculated table... it works perfectly

 

Go to Modelling Tab>>>NEW TABLE and then use this formula

 

DateTime =
ADDCOLUMNS (
    CROSSJOIN (
        CALENDAR ( MIN ( Invoice[NvDate] ), MAX ( Invoice[NvDate] ) ),
        UNION (
            ROW ( "Time", TIME ( 1, 0, 0 ) ),
            ROW ( "Time", TIME ( 2, 0, 0 ) ),
            ROW ( "Time", TIME ( 3, 0, 0 ) ),
            ROW ( "Time", TIME ( 4, 0, 0 ) ),
            ROW ( "Time", TIME ( 5, 0, 0 ) ),
            ROW ( "Time", TIME ( 6, 0, 0 ) ),
            ROW ( "Time", TIME ( 7, 0, 0 ) ),
            ROW ( "Time", TIME ( 9, 0, 0 ) ),
            ROW ( "Time", TIME ( 10, 0, 0 ) ),
            ROW ( "Time", TIME ( 11, 0, 0 ) ),
            ROW ( "Time", TIME ( 12, 0, 0 ) ),
            ROW ( "Time", TIME ( 13, 0, 0 ) ),
            ROW ( "Time", TIME ( 14, 0, 0 ) ),
            ROW ( "Time", TIME ( 15, 0, 0 ) ),
            ROW ( "Time", TIME ( 16, 0, 0 ) ),
            ROW ( "Time", TIME ( 17, 0, 0 ) ),
            ROW ( "Time", TIME ( 18, 0, 0 ) ),
            ROW ( "Time", TIME ( 19, 0, 0 ) ),
            ROW ( "Time", TIME ( 20, 0, 0 ) ),
            ROW ( "Time", TIME ( 21, 0, 0 ) ),
            ROW ( "Time", TIME ( 22, 0, 0 ) ),
            ROW ( "Time", TIME ( 23, 0, 0 ) ),
            ROW ( "Time", TIME ( 24, 0, 0 ) )
        )
    ),
    "DateTime", [Date] + [Time]
)

 

 

@unclejemima

 

This is what i get when i use your code as a "calculated table" with a dummy Invoice table of 2 rows

 

functionexpects.png

Hmmm...it might be because I already have a column in my calender called "Date"and its trying to make another with the DAX?

 

Its supposed to give me this...

 

large.png

@unclejemima

 

So you are using it as a calculated Column????

 

haha.  I'm such a noob. I have no clue.


The screenshot came from this thread   http://community.powerbi.com/t5/Desktop/how-to-build-a-calendar-table-with-date-and-time/m-p/374493#.......and it looked exactly what I wanted to do.

 

Basically I have a calender table and I'm trying to get hours and minutes on it...so I went to my existing Calender table, made a new calculation column, pasted the formula in my first post in and keep getting the error.


Is it not supposed to be a calculated column?

 

 

Hi @unclejemima

 

Yes... AddColumn is a function which returns a Table......It cannot be used in Calculated Columns and Measures....Directly..

 

However you can use this code as a CALCULATED TABLE
So if you go to Modelling Tab>>New Table and paste this code...you will get an entirely new Table in your Model

 

 

 

Epic!  You are awesome!!!

 

Well, there was one to many comma's though in the first formula right?  So you helped me figure that as well 🙂

 

Thank you!!!!!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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