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! Learn more

Reply
Anonymous
Not applicable

Calculated column for each row across multiple tables

Hi everyone,

 

I have a table 'ClientInfo' which has (among others) three columns: BeginDate, EndDate, TotalCostsPerDay. Additionally, I have a table called 'DateValues' which has a column called 'Dates'.

 

I want to add a calculated column 'AggregateCostPerDay' to 'DateValues', where the n-th value is defined as follows:

 

- Take the 'DateValues'[Dates] value of the n-th row (call this date 'x');
- Get all rows of 'ClientInfo' where the date-range (BeginDate, EndDate) contains this date 'x';
- For these rows, take the sum of the 'TotalCostPerDay' values;
- This sum is the n-th vale of the 'AggregateCostPerDay' column.

 

I have the following DAX statement, which is not working:

 

'DateValues'[AggregateCostPerDay] = CALCULATE(SUMX( FILTER(ClientInfo, BeginDate <= 'DateValues'[Dates] && 'DateValues'[Dates] <= EndDate) ))

 

It's not working because inside the SUMX, 'DateValues'[Dates] is the problem. I would need something like:

 

'DateValues'[AggregateCostPerDay] = For each 'Date' in 'DateValues'[Dates], CALCULATE(SUMX( FILTER(ClientInfo, BeginDate <= 'Date' && 'Date' <= EndDate) ))

 

How would I have to do this?

 

Thanks in advance!

1 REPLY 1
Stachu
Community Champion
Community Champion

try this as a calculated column in 'DateValues'

AggregateCostPerDay =
VAR __Date = 'DateValues'[Dates]
VAR __ClientInfo =
    FILTER (
        'ClientInfo',
        'ClientInfo'[BeginDate] <= __Date
            && 'ClientInfo'[EndDate] >= __Date
    )
RETURN
    SUMX ( __ClientInfo, [TotalCostsPerDay] )

if it doesn't work - can you add sample tables (in format that can be copied to PowerBI) from your model with anonymised data? Like this (just copy and paste into the post window).

Column1Column2
A1
B2.5

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.