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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Lookup dates dynamically for each row of data from a seperate table within a measure

Hi Everyone

I have a problem and could someone please help out. I have two tables, a Sales Table showing the dailysale of outlets and an Agrement Table showing the Validity start and end date for each outlet. The outlet Code/Name is the common field connecting both tables and acting as the relationship.

 

The problem is that Sales can be done to outlets even after their agreement is expired and so i want to split my total sales to each outlet by what is valid (Within the agreement start and end Date) and what sales have been done as miscouduct (Sales to outlet beyond agreement timeline)

 

Sales Table(YTD SFA Table) 
OutletDaySale
A01-01-1910
A02-02-1975
A03-03-1920
A08-08-1990
B05-05-1945
B06-06-1935
C01-01-19150
C07-07-1925

 

Agreement( TieUp)  
Outlet TableValid StartValid EndSale within valid period (Desired results)
A01-05-1830-04-19105
B01-06-1901-06-2035
C01-01-1931-12-19175

 

I have gonnen there partially with the folloing code:

 

Sale Between = CALCULATE(SUMX('YTD SFA RD', 'YTD SFA RD'[QTY sold (Only in CS)]) , DATESBETWEEN( 'YTD SFA RD'[Order Confirm Date],
    LOOKUPVALUE(TieUp[Agreement - From] , TieUp[Outlet Code] , MAX( 'YTD SFA RD'[Outlet Code] ) ),
    LOOKUPVALUE(TieUp[Agreement - To] , TieUp[Outlet Code] , MAX( 'YTD SFA RD'[Outlet Code])
)))
 
I cannot get the lookupvalue function to bring in the Agreement Start date and The Agreement End date form my Agreement Table (Tieup).
The start and end dates will differ from outlet to outlet.
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous  Thank you, this worked for me.

 

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@Anonymous 

 

Hope you have established the relationship between both the table with the Outlet name.

 

Create an measure with the below DAX

 

Measure =  CALCULATE( SUM(Table1[Sale]),

FILTER(Table1,Table1[Day]>=RELATED(Table2[Valid Start]) && Table1[Day]<=RELATED(Table2[Valid End])))

Measure.JPG
 
Nandri
Anonymous
Not applicable

@Anonymous  Thank you, this worked for me.

 

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.