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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors