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
cocoloco79
Helper II
Helper II

Subtracting days form date

Hi there

 

I have two tables for witch I have created a relationship that looks at crop.

One table holds a harvest date column and the other table holds number of days to grow plants.

 

I like to subtract the number of days from the harvest date to calculate the planting date.

Can anyone help me with this?

date calc.png

 

 

3 ACCEPTED SOLUTIONS
cocoloco79
Helper II
Helper II

Hi Steve, thank you but this didnt work. I get an error stating that the column gow time doesnt exist or there is a relationship missing. I did create the relationship, but it is not beeing picket up in the function.

I have attached the pbix, I hope you don't mind thinking a look.

grow time.pnghttps://drive.google.com/file/d/1uZFHig9Jnv_6R1n1EONixlZ8UNBZbciF/view?usp=sharing 

 

 

View solution in original post

Hey @cocoloco79 . The relationship you had was many-to-many which is problematic. I updated your .pbix and it is linked here

 

This was the relationship in your file:

SteveHailey_0-1641092816550.png

 

I use this code to create a bridge table:

 

Grow Times = ALL( BI_Planting_Master[CropName], BI_Planting_Master[CropGrowTime])

 

SteveHailey_1-1641092842998.png

 

And then updated the relationships:

SteveHailey_2-1641092883985.png

And then updated the fields in the table visual:

SteveHailey_3-1641093096533.png

 

Someone else may have a better way to do this.. but this is they way I know. Hope that works for you!

 

-Steve

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
cocoloco79
Helper II
Helper II

Hi Steve, thank you but this didnt work. I get an error stating that the column gow time doesnt exist or there is a relationship missing. I did create the relationship, but it is not beeing picket up in the function.

I have attached the pbix, I hope you don't mind thinking a look.

grow time.pnghttps://drive.google.com/file/d/1uZFHig9Jnv_6R1n1EONixlZ8UNBZbciF/view?usp=sharing 

 

 

Hey @cocoloco79 . The relationship you had was many-to-many which is problematic. I updated your .pbix and it is linked here

 

This was the relationship in your file:

SteveHailey_0-1641092816550.png

 

I use this code to create a bridge table:

 

Grow Times = ALL( BI_Planting_Master[CropName], BI_Planting_Master[CropGrowTime])

 

SteveHailey_1-1641092842998.png

 

And then updated the relationships:

SteveHailey_2-1641092883985.png

And then updated the fields in the table visual:

SteveHailey_3-1641093096533.png

 

Someone else may have a better way to do this.. but this is they way I know. Hope that works for you!

 

-Steve

SteveHailey
Solution Specialist
Solution Specialist

Hello,

One option is to create a calculated column in your Harvest Date table to pull in the grow time from the related table:

 

 

Grow Time = RELATED('Grow Times'[CropGrow Time] )

 

 

 Then add a calculated column to subtract the days:

 

 

Planting Date = 'Harvest Date'[Date] - 'Harvest Date'[Grow Time]

 

 

Then create a table visual to match your example:

SteveHailey_0-1641087234537.png

Here's a link to an example .pbix file.

 

-Steve

 

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.