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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ahmadov_10
Helper II
Helper II

We cannot convert the value #date to type Function

Hello Experts,

in Power Query editor i need to configure a StartDate and EndDate 

I maked this code and the formulas StartDate and EndDate works fine :

let

source ..... 

StartDate = Date.AddMonths(Date.StartOfMonth(DateTime.Date(DateTime.FixedLocalNow())), -13), // 01/06/2021
EndDate = Date.AddMonths(Date.EndOfMonth(DateTime.Date(DateTime.FixedLocalNow())), -1), // 30/06/2022
#"Addedstart" = Table.AddColumn(#"Changed Type", "StartDate", each Date.ToText(StartDate)),
#"Addedend" = Table.AddColumn(#"Addedstart", "EndDate", EndDate)
in
#"Addedend"

 

the problem in the step Addedstart : no errors but , not showing results in column  : so how to add correctly the value of variable and convert it to date @Vijay_A_Verma    @BA_Pete . thanks a lot

 

ahmadov_10_0-1657794861022.png

 

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @ahmadov_10 ,

 

You are missing "each" in this step, and it will throw an error "We cannot convert the value #date to type Function".

#"Addedend" = Table.AddColumn(#"Addedstart", "EndDate", EndDate)

 

Please try the following code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YlWcgKTzmDSRSk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    StartDate = Date.AddMonths(Date.StartOfMonth(DateTime.Date(DateTime.FixedLocalNow())), -13), // 01/06/2021
    EndDate = Date.AddMonths(Date.EndOfMonth(DateTime.Date(DateTime.FixedLocalNow())), -1), // 30/06/2022
    #"Addedstart" = Table.AddColumn(#"Changed Type", "StartDate", each Date.ToText(StartDate)),
    #"Addedend" = Table.AddColumn(#"Addedstart", "EndDate", each EndDate)
in
    #"Addedend"

vkkfmsft_0-1658195877045.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
v-kkf-msft
Community Support
Community Support

Hi @ahmadov_10 ,

 

You are missing "each" in this step, and it will throw an error "We cannot convert the value #date to type Function".

#"Addedend" = Table.AddColumn(#"Addedstart", "EndDate", EndDate)

 

Please try the following code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YlWcgKTzmDSRSk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    StartDate = Date.AddMonths(Date.StartOfMonth(DateTime.Date(DateTime.FixedLocalNow())), -13), // 01/06/2021
    EndDate = Date.AddMonths(Date.EndOfMonth(DateTime.Date(DateTime.FixedLocalNow())), -1), // 30/06/2022
    #"Addedstart" = Table.AddColumn(#"Changed Type", "StartDate", each Date.ToText(StartDate)),
    #"Addedend" = Table.AddColumn(#"Addedstart", "EndDate", each EndDate)
in
    #"Addedend"

vkkfmsft_0-1658195877045.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BA_Pete
Super User
Super User

Hi @ahmadov_10 ,

 

Why are you trying to apply a variale to a new column? Why not just write the variable calculation into the new column calculation instead?

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hello , thanks for answer : what I shared was a test but my business need is to create one column called date

between the variables startDate and EndDate. and i want to use it with many columns in my script Power Query , so it's interesting to use variables but i'm open for any suggestions. 

 

Ok, it sounds like we need to go back a step then.

Can you describe accurately what data you are starting with, and explain exactly what your end-goal is please?

It sounds like you actually want to do something quite simple, but are trying to go about it in an over-complicated or roundabout way: XY Problem 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors