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

Working with dates from multiple tables

There were a few posts on this but none that hit exactly what I need.

 

I have two tables - both are migration dates but one table is for PC migration, the other is for a Person that is being migrated.

 

I will need to report data that shows how many PC and people are being migrated per day, and how man actually got migrated (these are two more date columns).

 

My thoughts are to create a date table and have each table join to the date table - many to one relationship.  However I cannot connect by date as the dates have time in them also.  I tried sending them stright to int's to join the data by using:

FORMAT(TABLE[COLUMN], "YYYMMDD") however this doesn't seem to actually convert the data.

 

Can someone point out an easier way to do this, or help with the correct DAX expression to use?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

So, assuming that your date table does not have times and is in the format "yyyyMMdd", you should be able to create a new column in the table with the formula:

 

FormattedMigrationDate = FORMAT([MigrationDate],"yyyyMMdd")

 

Reference here: https://msdn.microsoft.com/en-us/library/ee634398.aspx

 

Then you can relate that table and the date table.

 

This is DAX, so this is in the data model.

 

Depending on what you are doing, this may be OK and you can use "USERELATIONSHIP" and specify the correct relationship. If not, you may have to create multiple date tables. I'd have to see your data and data model to know for sure.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
Greg_Deckler
Super User
Super User

So, assuming that your date table does not have times and is in the format "yyyyMMdd", you should be able to create a new column in the table with the formula:

 

FormattedMigrationDate = FORMAT([MigrationDate],"yyyyMMdd")

 

Reference here: https://msdn.microsoft.com/en-us/library/ee634398.aspx

 

Then you can relate that table and the date table.

 

This is DAX, so this is in the data model.

 

Depending on what you are doing, this may be OK and you can use "USERELATIONSHIP" and specify the correct relationship. If not, you may have to create multiple date tables. I'd have to see your data and data model to know for sure.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the reply.  I did try that and it just doesn't seem to accept the relationship.

 

Could it be a problem since most of the migrated dates are blank?

I'm beggining to think that the problem with joining using the new date table is maybe how I created it?  I just ripped something off the web.

 

Anybody see anything wrong with using this a date "dimension" table?

DimMigrationDate = 
ADDCOLUMNS (
    CALENDAR ( "1-jan-2015", "31-dec-2020" ),
    "DateID", FORMAT ( [Date], "YYYYMMDD" ),
    "Year", YEAR ( [Date] ),
    "Monthnumber", FORMAT ( [Date], "MM" ),
    "YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),
    "YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
    "MonthNameShort", FORMAT ( [Date], "mmm" ),
    "MonthNameLong", FORMAT ( [Date], "mmmm" ),
    "WeekNumber", WEEKNUM ( [Date], 1 ),
    "DayOfWeekNumber", WEEKDAY ( [Date] ),
    "DayOfWeek", FORMAT ( [Date], "dddd" ),
    "DayOfWeekShort", FORMAT ( [Date], "dddd" ),
    "Quarter", "Q" & FORMAT ( [Date], "Q" ),
    "YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q"
        & FORMAT ( [Date], "Q" )
)

One thing that is sticking out at me is that there is no column "Date" - this is what I'm using to create my relationship.  Sorry if this is all banter but I'm just not familiar with DAX.

 

I figured out that the data did not have migration date set to an actual date type.  This allowed me to join the data appropriately using one date table per migration type.  If there is a better way, i'd like to hear it!

I once experimented with having a central date table that I related to each of my individual date tables that were then related to the fact table. The idea was that I could at least use a central date table in all of my visualizations without having to worry about and remember which individual date table was related to a particular fact table column. It seemed to work but I think I saw some feedback that some people had some issues with this approach. Might be worth exploring.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi smoupre, I've been trying to approach my data model this way and running into an issue where I need to prioritize one a date from one table over another in certain instances. Did you run into something similar? An example would be I have social media campaign running that has a start date and then individual posts have their own dates. However, not all of the social media posts end up being associated with any particular campaign because they are just one off posts, etc. So when I display the results, I would like to see the date used by the campaign first and if it doesn't exist fall back to the date on the individual posts. Thoughts?

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.