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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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