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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Urgent -Start and end date issues

Hi everyone,

   I tried to fetch start and end date in single column by using functions in power query and added to invoked custom function while my start date and end date is same at that time it shows error from this power query 

(StartDate as date, EndDate as date) as table =>
let
Source = List.Dates(StartDate, Length, #duration(1, 0, 0, 0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table", {{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns", {{"Date", type date}}),
Length = Duration.Days(EndDate - StartDate)
in
#"Changed Type"

Capture.PNG

I attach my screenshot for your reference....kindly help me on this...

 

Advance thanks to all...

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
Employee

Just +1 to your length variable.  That also makes it so you see the end data in your list too.

 

(StartDate as date, EndDate as date) as table =>
let
Source = List.Dates(StartDate, Length, #duration(1, 0, 0, 0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table", {{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns", {{"Date", type date}}),
Length = Duration.Days(EndDate - StartDate)+1
in
#"Changed Type"

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could add IF() formula to avoid errors. If StartDate is the same as EndDate, it can return StartDate.

Length = 
if EndDate = StartDate then Duration.Days(EndDate +#duration(1, 0, 0, 0) - StartDate) 
else Duration.Days(EndDate - StartDate)

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

4 REPLIES 4
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could add IF() formula to avoid errors. If StartDate is the same as EndDate, it can return StartDate.

Length = 
if EndDate = StartDate then Duration.Days(EndDate +#duration(1, 0, 0, 0) - StartDate) 
else Duration.Days(EndDate - StartDate)

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
mahoneypat
Employee
Employee

Just +1 to your length variable.  That also makes it so you see the end data in your list too.

 

(StartDate as date, EndDate as date) as table =>
let
Source = List.Dates(StartDate, Length, #duration(1, 0, 0, 0)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table", {{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns", {{"Date", type date}}),
Length = Duration.Days(EndDate - StartDate)+1
in
#"Changed Type"

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@Anonymous , are you getting this error , While expanding the table with the icon at end of column name?

Anonymous
Not applicable

hi @amitchandak 

 

   Yes I am getting the error if the start date and end date is same at that row only shows error I already attached that with screenshot. Kindly help me on that

 

Thanks for your reply....

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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