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
Vroom_Master3
Helper I
Helper I

Need Help with DAX formula to SUM Values Based on Month in another Table

I have two tables, One for veryifying data agaisnt a target, and one for tracking the many lines of Cost entrires. 

Neither table has a specific way I can relate them as you can see below. 

 

TableA 

Date    |    Total_Cost    |    Location

Nov 1                     350                   A

Nov 6                     120                   A

Nov 6                     100                   B

Nov 6                     200                   C

Nov 12                    30                    A

...

Dates Repeat, Cost varies, and Location is either A,B, or C

 

TableB

MonthStart    |    MonthEnd    |    CostA    |    CostB    |    CostC

Nov 1, 23              Nov 30, 23             500              100         200

Dec 1, 23               Dec 31, 23                    ....

 

I need to be able to represent All costs for each location based off of a date range, I can't get around the usage of the date range in TableB. If i need to make more than 1 column that is super fine, but I cant figure out a way to compare the Dates in Table A and the Location and be able to acutally reference it. Every combination of TREATAS and CALCULATE i've thought of wont do it so I'm hoping you guys can help. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Vroom_Master3 ,

I'll show you my test data first, the date column data types in Table A and Table B are Date:

vjunyantmsft_0-1700100736845.png

vjunyantmsft_1-1700100784164.png

Then you can create three new columns with the following DAX:

CostA = 
CALCULATE(
    SUM(TableA[Total_Cost]),
    FILTER(
        'TableA',
        'TableA'[Date] >= 'TableB'[MonthStart] && 'TableA'[Date] <= 'TableB'[MonthEnd] && 'TableA'[Location] = "A"
    )
)
CostB = 
CALCULATE(
    SUM(TableA[Total_Cost]),
    FILTER(
        'TableA',
        'TableA'[Date] >= 'TableB'[MonthStart] && 'TableA'[Date] <= 'TableB'[MonthEnd] && 'TableA'[Location] = "B"
    )
)
CostC = 
CALCULATE(
    SUM(TableA[Total_Cost]),
    FILTER(
        'TableA',
        'TableA'[Date] >= 'TableB'[MonthStart] && 'TableA'[Date] <= 'TableB'[MonthEnd] && 'TableA'[Location] = "C"
    )
)

The final result is as follows:

vjunyantmsft_2-1700100866118.png

 

Best Regards,

Dino Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.




View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Vroom_Master3 ,

I'll show you my test data first, the date column data types in Table A and Table B are Date:

vjunyantmsft_0-1700100736845.png

vjunyantmsft_1-1700100784164.png

Then you can create three new columns with the following DAX:

CostA = 
CALCULATE(
    SUM(TableA[Total_Cost]),
    FILTER(
        'TableA',
        'TableA'[Date] >= 'TableB'[MonthStart] && 'TableA'[Date] <= 'TableB'[MonthEnd] && 'TableA'[Location] = "A"
    )
)
CostB = 
CALCULATE(
    SUM(TableA[Total_Cost]),
    FILTER(
        'TableA',
        'TableA'[Date] >= 'TableB'[MonthStart] && 'TableA'[Date] <= 'TableB'[MonthEnd] && 'TableA'[Location] = "B"
    )
)
CostC = 
CALCULATE(
    SUM(TableA[Total_Cost]),
    FILTER(
        'TableA',
        'TableA'[Date] >= 'TableB'[MonthStart] && 'TableA'[Date] <= 'TableB'[MonthEnd] && 'TableA'[Location] = "C"
    )
)

The final result is as follows:

vjunyantmsft_2-1700100866118.png

 

Best Regards,

Dino Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.




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.