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
gerget
Frequent Visitor

Dates Table Relationship

Dear all, 

 

I am having problems with creating a working relationship with the dates table I created in Power BI and unfortunately could not find a solution in the forum that worked for me.

I have an invoices table, which stores every sale that has been made, with the columns

  • createdon:                 date of the invoice
  • totalamount_EUR:     invoice value

So there is multiple entries per day (-> createdon column has duplicates).

Since I need a dates table for many calculations, I set one up in Power BI and tried to create a many-to-one relationship between the "createdon"[invoices] column and the "date"[dates] column in my dates table: 
RelationshipsRelationships
Now, once the relationship is active, a report table that shows the values for "date" (drawn from the dates table) and "totalamount_EUR" only lists all the values separately: when there's an entry in the "date" column, the "totalamount_EUR" column is empty and, vice versa, where there's values in the "totalamount_EUR" column there is no corresponding values for "date".

When I create a report table with the "totalamount_EUR" column and the "createdon" (instead of "dates") column, this problem does not appear!
It looks like this:

Report TablesReport Tables
Thus, I assume the relationship between createdon[invoices] and date[dates] does not work properly. 
The code I used to set up my dates table looks like this: 

Dates = 
  GENERATE (
    CALENDAR( DATE( YEAR( MIN(invoices[createdon]) ), MONTH(  MIN(invoices[createdon]) ), DAY( MIN(invoices[createdon]))), DATE( YEAR( MAX(invoices[createdon]) ), MONTH(  MAX(invoices[createdon]) ), DAY( MAX(invoices[createdon])))),
    VAR startOfWeek = 2    
    VAR currentDay = [Date]
    VAR days = DAY( currentDay )
    VAR months = MONTH ( currentDay )
    VAR years = YEAR ( currentDay )
    VAR nowYear = YEAR( TODAY() )
    VAR nowMonth = MONTH( TODAY() )
    VAR dayIndex = DATEDIFF( currentDay, TODAY(), DAY) * -1
    VAR todayNum = WEEKDAY( TODAY() )
    VAR weekIndex = INT( ROUNDDOWN( ( dayIndex + -1 * IF( todayNum + startOfWeek <= 6, todayNum + startOfWeek, todayNum + startOfWeek - 7 )) / 7, 0 ) )
  RETURN ROW (
    "day", days,
    "month", months,
    "year", years,
    "month year", months & "/" & years,
    "day index", dayIndex,
    "week index", weekIndex,
    "month index", INT( (years - nowYear ) * 12 + months - nowMonth ),
    "year index", INT( years - nowYear )
  )
)


Does anyone have an idea how to fix this? Thankful for advice!

Best regards
gerget

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@gerget,


Could you please share sample data of your invoices table here? 

As other's post, does the createdon column contain datetime values and you manually change the data type of the column to date? If so, the above issue will occur. You can create a calculated columns using dax below. Then create relationship between the new column and date column of dates table.

newCreatedon=DATE( YEAR(invoices[createdon]) , MONTH(  invoices[createdon] ), DAY( invoices[createdon]))




Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yuezhe-msft
Employee
Employee

@gerget,


Could you please share sample data of your invoices table here? 

As other's post, does the createdon column contain datetime values and you manually change the data type of the column to date? If so, the above issue will occur. You can create a calculated columns using dax below. Then create relationship between the new column and date column of dates table.

newCreatedon=DATE( YEAR(invoices[createdon]) , MONTH(  invoices[createdon] ), DAY( invoices[createdon]))




Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-yuezhe-msft ! This was very helpful. In PowerBi Desktop (April 2020) , you could also use Date.From. 

Dear Lydia,

 

this actually worked! Thank you so much for your help.

 

Best, 
gerget

dedelman_clng
Community Champion
Community Champion

Check for time values on your Invoice table. You may need to strip/convert in PowerQuery or in the source data.

 

17 Aug 2018 09:00:00 <> 17 Aug 2018 00:00:00

 

Hope this helps

David

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.