Forum Discussion

cocoloco79's avatar
cocoloco79
Icon for Helper III rankHelper III
4 years ago
Solved

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?

 

 

  • 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:

     

    I use this code to create a bridge table:

     

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

     

     

    And then updated the relationships:

    And then updated the fields in the table visual:

     

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

     

    -Steve

4 Replies

  • SteveHailey's avatar
    SteveHailey
    Icon for Solution Specialist rankSolution 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:

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

     

    -Steve

     

    • SteveHailey's avatar
      SteveHailey
      Icon for Solution Specialist rankSolution Specialist

      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:

       

      I use this code to create a bridge table:

       

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

       

       

      And then updated the relationships:

      And then updated the fields in the table visual:

       

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

       

      -Steve