Forum Discussion

Dunner2020's avatar
Dunner2020
Post Prodigy
5 years ago
Solved

Relationship between two tables

Hi there,   I have two tables: one with five years' average value and the other is the date table. Five years' average value has one to many relationships with the date table. 'RY Month' column of ...
  • edhans's avatar
    edhans
    5 years ago

    The direction of the line shows the filter direction. So your data table is filtering the date table. That is backwards. The Date table is a DIM (Dimension) table and should always filter the FACT (or data) table.
    Do this:

    Add this formula to your data table and call it Date. This is in Power Query. Add a new custom column. This is the formula.

    if Date.EndOfMonth(Date.FromText([month] & "1, " & Text.From(Date.Year(DateTime.LocalNow())))) > DateTime.Date(DateTime.LocalNow())
    then Date.AddYears(Date.EndOfMonth(Date.FromText([month] & "1, " & Text.From(Date.Year(DateTime.LocalNow())))), -1) 
    else Date.EndOfMonth(Date.FromText([month] & "1, " & Text.From(Date.Year(DateTime.LocalNow()))))

    Now, that may not be right. What it returns is this (I hid columns for the sake of space)

    Now connect that date column to the Date column in the Date table. It should be a one to many from the Date table pointing to the fact table. 

    Now the date table fields should be used in your visuals and will work.

    If that is not the correctly calculated date, show me what it should be. Basically I said get the month name (jan, feb, mar) and make it the last day of month for this year, unless it is the future, then make it last year.