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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Oberon
Frequent Visitor

Create column where a date row value = sum of values between start & end date on another table

Hi,

 

I'm new to Power BI and trying to figure out how to get the equivilent of an excel sumif referencing dates on another table.

 

Assuming Table A looked like this example:

Table A

NameStart DateEnd DateFTE

Joe

1/1/202122/12/20231
Fred1/1/20213/04/20221
Jill1/1/20211/1/20991
Kate1/1/20211/1/20991

 

And I had dates in the first column of Table B.

I'm looking to try and get the 2nd column "Sum of FTE" as a calculated column returning:

Sum of table A[FTE] if Table A [Start Date] is less than or equal Table B[Date] and Table A[End Date] is above Table B[Date]

 

Table B

DateSum of FTE
1/04/20223
2/04/20223
3/04/20222
4/04/20222
5/04/20222
4/04/20222

 

I've tried various combinations of methods but nothing quite gets there. For the most part it tells me I can't reference 2 seperate tables or the value I return from the other table is a single value and not related to the date in Column A of Table B.

1 ACCEPTED SOLUTION

5 REPLIES 5
lbendlin
Super User
Super User

Please do not use fake end dates. Much better to leave these blank.

 

lbendlin_0-1708481542045.png

Sum of FTE =
VAR a =
    SUMMARIZECOLUMNS ( Dates[Date], Emps[Start Date], Emps[End Date], Emps[FTE] )
VAR b =
    ADDCOLUMNS (
        a,
        "ct",
            COUNTROWS (
                INTERSECT (
                    { [Date] },
                    CALENDAR ( [Start Date], COALESCE ( [End Date], TODAY () ) )
                )
            )
    )
RETURN
    SUMX ( b, [ct] * [FTE] )

see attached

 

Thank you Ibendlin,

 

It's great to see it can be done. I've tried adapting this to my specific data and I get and error saying the start date of the calendar function cannot be later than the end date. (I've done as you mentioned and removed the fake end dates from the sorce data so the values return null).

 

I suspect my error may have been in providing only historic data in the example when I'm attempting to use it for future dated changes as well. This is what I have at present in case there's any glaring syntax errors in the code I've adapted.

Sum of FTE = 
VAR a = 
    SUMMARIZECOLUMNS ( FTESum[Date], FTEImportData[Start Date], FTEImportData[End Date], FTEImportData[FTE] ) 
VAR b = 
    ADDCOLUMNS ( 
        a, 
        "ct", 
            COUNTROWS ( 
                INTERSECT ( 
                    { [Date] }, 
                    CALENDAR ( [Start date], COALESCE ( [End date],TODAY() ) ) 
                ) 
            ) 
    ) 
RETURN 
    SUMX ( b, [ct] * [FTE] ) 

I've tried playing with changing the formula of Today () to Date and/or adding a coalesce with a historic date to the start date as well but the only other variation of the error I get is that the start or end date can't return null.  Any ideas on where I'm going wrong?

when I'm attempting to use it for future dated changes as well.

yes, you may have wanted to mention that.

 

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Apologies, rookie mistake. (Litereally my first Power BI attempt).  I'm still adapting my thinking away from Excel where that would have been an easy adaptation for me.

 

This is a sample of clensed data from the table I'm using.

Agent NameEmployee IDFTEDeptStart dateEnd date
Name 1195000011Migrations1/01/2024 
Name 2195000021Coach1/01/202418/02/2024
Name 3195000031SME1/01/2024 
Name 4195000041Consumer1/01/202427/08/2024
Name 5195000051SME1/01/2024 
Name 6195000061Consumer1/01/20241/04/2024
Name 7195000071Consumer1/01/202430/06/2024
Name 8195000081Premium1/01/2024 
Name 9195000090.6SME1/01/2024 

 

The 2nd table remains the same to begin with just cronological dates.

 

I was looking to tackle the sum of FTE for each date first then work out if I needed a (sum of FTE) column for each department seperately or could just link in the data model and use a slicer so I'll mention that in case it's relevant.

lbendlin_0-1708566040513.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Kudoed Authors