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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
MikeBro
Frequent Visitor

how to get values other records in a table based on the current row contents

Newbie here on DAX

 

I have a table of contracts containing ID, contract name, customer ID, start date, end date and type, value. The table holds the list of contracts the customer has with us but also conains entries for contracts to be made live when they renew. So we would have something like:

 

IDnamecust idstartendtypevalue
111support contract 2023AA9991/1/2331/12/23service 11000
567support contract 2024AA9991/1/2431/12/24service 11200

 

 

I want to be able to show in a table visual the old versus the new values (and dates etc)

 

I want something that finds the 'next years' contract data (if one exists) by matching the customer ID, type and the (end date of current + 1 day) == start date of next year. In reality there are other parameters in the table that I can also match on to make sure I am picking the correct pair of contracts as there can be multiple current and future contracts per customer.

 

I tried a few things but can't get my head around it. I need a pointer to start and I will work out the details.

1 ACCEPTED SOLUTION
rbriga
Impactful Individual
Impactful Individual

Perhaps a simple solution would not be in DAX at all.

You can create a second fact table for future contracts with a start and end date to connect them.

 

As for a DAX solution, this worked for my testing grounds:

Next Contract Value = 
SUMX(Contracts,
    VAR _NextContractStart= Contracts[Contract End]+1
    RETURN
    CALCULATE(SUM(Contracts[Value]),
    ALLEXCEPT(Contracts,Contracts[Customer]),
    KEEPFILTERS(Contracts[Contract Start]=_NextContractStart)
    )
)

 

Victory!Victory!

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!

View solution in original post

2 REPLIES 2
MikeBro
Frequent Visitor

Thanks, that worked. I was thinking about duplicating the table (which didn't seem sensible) or doing something with virtual tables (which I couldn't get my hea around).

rbriga
Impactful Individual
Impactful Individual

Perhaps a simple solution would not be in DAX at all.

You can create a second fact table for future contracts with a start and end date to connect them.

 

As for a DAX solution, this worked for my testing grounds:

Next Contract Value = 
SUMX(Contracts,
    VAR _NextContractStart= Contracts[Contract End]+1
    RETURN
    CALCULATE(SUM(Contracts[Value]),
    ALLEXCEPT(Contracts,Contracts[Customer]),
    KEEPFILTERS(Contracts[Contract Start]=_NextContractStart)
    )
)

 

Victory!Victory!

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.