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
Syndicate_Admin
Administrator
Administrator

It won't let me subtract two dates

Good.

I'm trying to subtract two dates, but I can't, since when creating the measure it doesn't show me the date fields of the table I need, my measurement would be:

difference = DATEDIFF( Contracts[FROM]:, Dcontratos[UNTIL], DAY)

In the following screenshot you can see how I have defined the dates:

fecha2.png

Format

fecha3.png

when creating the measure I do not see the from field:

fecha4.png

Structure and representation

fechas1.png

What's wrong?

Thanks a lot.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Syndicate_Admin No, I mean something like this:

diff_measure=var startDate=MIN([DESDE:])

var endDate=MAX([HASTA:])

return DATEDIFF(startDate,endDate,DAY)

 

Variables startDate and endDate you can define in any other way. But using variables you doesn't need DATEDIFF function to substract two dates, you can just substract those variables:

diff_measure=var startDate=MIN([DESDE:])

var endDate=MAX([HASTA:])

return endDate-startDate

 

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

@Syndicate_Admin In DATEDIFF function you have to use single value dates instead of date columns. Use variable to define start/end dates and then use them in the function.

Good you mean this:

fecha5.png

I put it like that, but it still doesn't leave me.

Anonymous
Not applicable

@Syndicate_Admin No, I mean something like this:

diff_measure=var startDate=MIN([DESDE:])

var endDate=MAX([HASTA:])

return DATEDIFF(startDate,endDate,DAY)

 

Variables startDate and endDate you can define in any other way. But using variables you doesn't need DATEDIFF function to substract two dates, you can just substract those variables:

diff_measure=var startDate=MIN([DESDE:])

var endDate=MAX([HASTA:])

return endDate-startDate

 

Hello my problem is when choosing the format of the measurement data. It doesn't let me choose more than dates. No numbers, can you help me?

apalomov_0-1660124917737.png

Resolved with Convert (Date, Integer)

OK, with the alegro.

Have you tried to change the data type to number, from Power Query?

Thank you very much, it has worked for me, I have finally used the today in Star to calculate today.

Greetings

Anonymous
Not applicable

@Syndicate_Admin Then you can accept my response as a solution)

It is already accepted.

Greetings

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.