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
bnjmnnl
Helper III
Helper III

DAX lookup within date and with same ID

Hello all, 

For making a calculation I need some help of the experts on here haha. 

I have two tables that represent the costs lines for certain transports. Table 1 shows the lines with currencies and table 2 shows the lines with %  and are based on certain values of table 1. I will show an example below:

Table 1     
ContractCosttypeObjectAmountCurrencyRESULT (calculate)
1tra234150EUR15
1admin23410EUR0
1handling23450EUR0
2tra222150EUR15
3tra211130EUR0
3admin21112EUR15
      
      
      
      
Table 2     
ContractCosttypeObjectAmountCurrencyCalculatefrom
1fuel23415%tra
2fuel22215%tra
3fuel21115%admin


The solution must result in the resultcolumn descirbed in Table 1. The percentage amount must be placed in the right row based on a link between costtype from table1 and calculatefrom from table 2. This wouldn't be too hard, but there is another issue. The amount have certain validities, based on a startdate column and an enddate column. The fuel costs don't need to have the exact same validity dates as the other ones within the same contract. I want to have the right percentage (from table 2) that was valid between the dates of the cosstype in table 1. 
Im not sure if this will be possible, otherwise please provide me the solution when there are no more dates but only the latest valid ones. 

Thank you in advance! If more info needed, please ask me!!!!

1 ACCEPTED SOLUTION

Ok then updated the measure

 

RESULT =
VAR CurrentContract = Table1[Contract]
VAR CurrentCosttype = Table1[Costtype]
VAR CurrentObject = Table1[Object]
VAR CurrentAmount = Table1[Amount]
VAR CurrentStartDate = Table1[startdate]
VAR CurrentEndDate = Table1[enddate]

VAR RelatedRow =
CALCULATETABLE(
Table2,
Table2[Contract] = CurrentContract,
Table2[Object] = CurrentObject,
Table2[Calculatefrom] = CurrentCosttype,
Table2[startdate] <= CurrentStartDate,
Table2[enddate] >= CurrentEndDate
)

VAR Percentage = MAXX(RelatedRow, Table2[Amount])

RETURN
IF(
ISBLANK(Percentage),
0,
CurrentAmount * Percentage / 100
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

3 REPLIES 3
bhanu_gautam
Super User
Super User

@bnjmnnl   , You can create a calculated column in Table 1 for this 

Result =
VAR CurrentContract = Table1[Contract]
VAR CurrentObject = Table1[Object]
VAR CurrentCostType = Table1[Costtype]
VAR CurrentAmount = Table1[Amount]
VAR RelatedRow =
CALCULATETABLE(
Table2,
Table2[Contract] = CurrentContract,
Table2[Object] = CurrentObject,
Table2[Calculatefrom] = CurrentCostType
)
VAR Percentage = MAXX(RelatedRow, Table2[Amount])
RETURN
IF(
Table1[Costtype] = "tra",
CurrentAmount * (Percentage / 100),
0
)

 

If you need to consider date validity, you can add additional conditions to the CALCULATETABLE function to filter based on the date range.

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hello, 

 

Thank you for tehg reply, 
However the caluclated costs don't need to be "tra". It can be much more than tra

 

Ok then updated the measure

 

RESULT =
VAR CurrentContract = Table1[Contract]
VAR CurrentCosttype = Table1[Costtype]
VAR CurrentObject = Table1[Object]
VAR CurrentAmount = Table1[Amount]
VAR CurrentStartDate = Table1[startdate]
VAR CurrentEndDate = Table1[enddate]

VAR RelatedRow =
CALCULATETABLE(
Table2,
Table2[Contract] = CurrentContract,
Table2[Object] = CurrentObject,
Table2[Calculatefrom] = CurrentCosttype,
Table2[startdate] <= CurrentStartDate,
Table2[enddate] >= CurrentEndDate
)

VAR Percentage = MAXX(RelatedRow, Table2[Amount])

RETURN
IF(
ISBLANK(Percentage),
0,
CurrentAmount * Percentage / 100
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors