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

Cross Join Table With End Dates

I am trying to create a table for budgeting that joins the staff table to a date table, with the intention of ending up with 1 row for each day and each staff member like so :

01/07/2019M.Mouse
02/07/2019M.Mouse
03/07/2019M.Mouse
04/07/2019M.Mouse
01/07/2019D.Duck
02/07/2019D.Duck
03/07/2019D.Duck
04/07/2019D.Duck

I can do this easily by creating a table with a cross join 

Daily Targets = crossjoin(values('Calendar'[Date]),VALUES('Staff'[Staff ID]))
However my staff table has start and finish dates and I want my Daily Targets table to only create records for the dates that each person was employed. So if M. Mouse leaves on 02/07/2019 The example becomes
01/07/2019M.Mouse
02/07/2019M.Mouse
01/07/2019D.Duck
02/07/2019D.Duck
03/07/2019D.Duck
04/07/2019D.Duck

Is this possible?

2 ACCEPTED SOLUTIONS
slanka
Helper I
Helper I

Hi,

 

There is no direct way of filter the rows when you are joining the tables using CROSSJOIN. Instead, after doing a crossjoin, you can create a calculated column that will give status to each row and you can pull ONLY on the dates when employee have start date and end date by using report level filter IsActive = 1.

View solution in original post

danextian
Super User
Super User

Hi @Pink1623 ,

Have you tried using Power Query instead? You can create a custom column to generate a list of dates starting from employment start to end and if end is null then use today's date. After creating a column of lists, you can expand it to new rows. Here's a sample code and some screenshots

let 
end  = if [End] = null then Date.From(DateTime.LocalNow())
else [End],
duration = Duration.Days(end - [Start]) + 1
in
List.Dates([Start], duration, #duration(1,0,0,0))


list of dates.png

expand to new rows.png

 

 

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @Pink1623 ,

Have you tried using Power Query instead? You can create a custom column to generate a list of dates starting from employment start to end and if end is null then use today's date. After creating a column of lists, you can expand it to new rows. Here's a sample code and some screenshots

let 
end  = if [End] = null then Date.From(DateTime.LocalNow())
else [End],
duration = Duration.Days(end - [Start]) + 1
in
List.Dates([Start], duration, #duration(1,0,0,0))


list of dates.png

expand to new rows.png

 

 

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks for your help

slanka
Helper I
Helper I

Hi,

 

There is no direct way of filter the rows when you are joining the tables using CROSSJOIN. Instead, after doing a crossjoin, you can create a calculated column that will give status to each row and you can pull ONLY on the dates when employee have start date and end date by using report level filter IsActive = 1.

Thanks Slanka, good to know

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.