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

Data type is wrong?

Hi guys! First of all Happy New Year.

 

I´m working on a report for my work which has a lot of projects with their respective last update on the database. I´m making a function that calculates the days since the last update. The problem is that I´m having negative numbers and inconsistencies.

 

The function for the Column " Days since Last Update" is: 

Days since Last Update = TODAY()-'TPA Portfolio'[Last Update Date]

 

It´s important to remark that the Last Update Date column is stated by PowerBI as a Text field and the format is DD/MM/YYYY (Argentinian date)

 

Capture.JPG

 

Thanks for your help...

1 ACCEPTED SOLUTION

Nowhere. It was just an example to illustrate the solution.

 

In your case, go to the Query Editor, select your column with textual dates and adjust the data type using Locale.

 

The video below illustrates how; it starts already in the Query Editor.

 

Here is the Query EditorHere is the Query Editor

 

 

 

Specializing in Power Query Formula Language (M)

View solution in original post

8 REPLIES 8
Interkoubess
Solution Sage
Solution Sage

Hi @Anonymous,

 

What about using the datediff function for this issue...

 

Let us know

Anonymous
Not applicable

Days since Last Update = DATEDIFF(TODAY(),'TPA Portfolio'[Last Update Date],DAY)

 

And I´m getting: In DATEDIFF function, the start date cannot be greater than the end date

 

I think the Power BI is messing between the date format of my PC (which is English format mm/dd/yyyy) and the format of the data base

Check the syntax of the DATEDIFF function.

 

The start date should be supplied first.

Specializing in Power Query Formula Language (M)
Anonymous
Not applicable

I dont think that the syntax is the problem. I'm guessing that the problem is on the date formats.

In that case you have more than 1 problem.

 

You can convert text dates to real dates in the Query Editor.

 

And still you need to provide the earlier date as the first parameter to DATEDIFF.

 

You may think otherwise, but the syntax is quite clear:

 

DATEDIFF(<start_date>, <end_date>, <interval>) 

You may consider providing more information if you want helpful help.

 

Specializing in Power Query Formula Language (M)

This query TPA Portfolio:

 

let
    Source = #table(type table[Last Update Date = text],{{"31/12/2017"}}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Last Update Date", type date}}, "es-AR")
in
    #"Changed Type"

 

works fine with this custom column:

 

Days since Last Update = DATEDIFF('TPA Portfolio'[Last Update Date],TODAY(),DAY)

 

DateDIFF.png

 

 

Convinced?

Specializing in Power Query Formula Language (M)
Anonymous
Not applicable

First of all, I appreciate your help.

 

Where do I have to insert that syntax function? 

let
    Source = #table(type table[Last Update Date = text],{{"31/12/2017"}}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Last Update Date", type date}}, "es-AR")
in
    #"Changed Type" 

 

Nowhere. It was just an example to illustrate the solution.

 

In your case, go to the Query Editor, select your column with textual dates and adjust the data type using Locale.

 

The video below illustrates how; it starts already in the Query Editor.

 

Here is the Query EditorHere is the Query Editor

 

 

 

Specializing in Power Query Formula Language (M)

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.