Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
agouveia
Frequent Visitor

Crossjoin with filters and unique date values

Hello,

 

I'm looking into creating a report that is able to take snapshots of past data and show how it looked liked at a certain past date. 

I have access to the history of the data but I need to create a crossjoin between my history data and my calendar.

 

My history table looks like this:

 

Id                  Date                       Status

1               18/08/2023                To do

1               20/08/2023             In Progress

2               20/08/2023                Testing

2               21/08/2023                 Done

 

...and what I want it to look like:

 

Id               Date                       Status

1           18/08/2023                 To do

1           19/08/2023                 To do

1           20/08/2023             In progress

1           21/08/2023             In progress

1           22/08/2023             In progress

2           20/08/2023                Testing

2           21/08/2023                 Done

2           22/08/2023                 Done

 

Basically, I want to have a row for each day until the current date with the associated state until there's a change to the satus. The last status update would be dragged until the current date. I have reach a partial solution but I'm getting duplicate dates for each Id:

 

MaxDate = 
CALCULATE(max('Card History'[Date]),filter('Card History', 'Card History'[Id]=EARLIER('Card History'[Id])))

MinDate=
CALCULATE(min('Card History'[Date]),filter('Card History', 'Card History'[Id]=EARLIER('Card History'[Id])))


Latest = 
ADDCOLUMNS (
    FILTER(
    CROSSJOIN(
    SUMMARIZECOLUMNS( 'Card History'[Id], 'Card History'[DateTime],  'Card History'[MinDate], 'Card History'[MaxDate],'Card History'[Name]),DISTINCT('Calendar'[Date] )),

'Calendar'[Date]>= 'Card History'[MinDate] && 'Calendar'[Date] <= 'Card History'[MaxDate]),


 "@Qty",
    VAR maxtime =
        CALCULATE ( MAX ( 'Card History'[DateTime] ))
    RETURN
        CALCULATE (DISTINCTCOUNT('Card History'[Id]),filter('Card History', 'Card History'[DateTime] = maxtime && 'Card History'[Index]='Card History'[Id] )
))

 

 

Any help would be appreciated!

Thanks!

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can use

New table =
GENERATE(
	VALUES( 'Calendar'[Date] ),
	SELECTCOLUMNS(
		INDEX(
			1,
			FILTER(
				ALL( 'Card History' ),
				'Card History'[Date] <= 'Calendar'[Date]
			),
			ORDERBY( 'Card History'[Date], DESC ),
			PARTITIONBY( 'Card History'[Id] ),
			MATCHBY( 'Card History'[Id], 'Card History'[Date] )
		),
		"Id", 'Card History'[Id],
		"Status", 'Card History'[Status]
	)
)

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

You can use

New table =
GENERATE(
	VALUES( 'Calendar'[Date] ),
	SELECTCOLUMNS(
		INDEX(
			1,
			FILTER(
				ALL( 'Card History' ),
				'Card History'[Date] <= 'Calendar'[Date]
			),
			ORDERBY( 'Card History'[Date], DESC ),
			PARTITIONBY( 'Card History'[Id] ),
			MATCHBY( 'Card History'[Id], 'Card History'[Date] )
		),
		"Id", 'Card History'[Id],
		"Status", 'Card History'[Status]
	)
)

Hi @johnt75 ,

 

This could work but it doesn't add all the dates between the min date and max date of each Id. Anyway I could add those dates in between each status?

 

Best

It should work fine as long as you have all the dates in your calendar table. I ran a test using your sample data and it came back with the results you were expecting.

Yes, correct. I had a relationship to my calendar and that wasn't working but it's fine without it now. Thanks.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.