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
Anonymous
Not applicable

calculate 2 columns during a date interval

hello i have 2 table:

table_a_Date  table_a_cost  table_b_Date  table_b_cost
1/2/2022  10  1/2/2022  20
1/3/2022  5  1/3/2022  4
1/4/2022  3  1/4/2022  5
1/5/2022  6  1/5/2022  1
1/6/2022  8  1/6/2022  29
1/7/2022  1  1/7/2022  34
1/8/2022  10  1/8/2022  5
1/9/2022  5  1/9/2022  1
1/10/2022  4  1/10/2022  5

 

i want to make a measure that finds difference as: sum(table_a[cost]) - sum(table_b[cost])

but i want to specify a specific date like i want it to calculate the difference from 1/6/2022 till 1/10/2022 and so on but the rest of the days before 1/6/2022 just gives me 0

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 
You can use 

Measure = 
SUMX (
    VALUES ( table_a[table_a_Date] ),
    CALCULATE ( 
        IF ( 
            MAX ( table_a[table_a_Date] ) >= DATE ( 2022, 1, 6 ),
            MAX ( table_a[table_a_cost] ) 
                - CALCULATE ( 
                    SUM ( table_b[table_b_cost] ), 
                    table_b[table_b_Date] = MAX ( table_a[table_a_Date] ) 
                ),
            0
        )
    )
)

1.png

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @Anonymous 
You can use 

Measure = 
SUMX (
    VALUES ( table_a[table_a_Date] ),
    CALCULATE ( 
        IF ( 
            MAX ( table_a[table_a_Date] ) >= DATE ( 2022, 1, 6 ),
            MAX ( table_a[table_a_cost] ) 
                - CALCULATE ( 
                    SUM ( table_b[table_b_cost] ), 
                    table_b[table_b_Date] = MAX ( table_a[table_a_Date] ) 
                ),
            0
        )
    )
)

1.png

amitchandak
Super User
Super User

@Anonymous , option one is that you can have a common date table and then you can join with the date of both tables and use date from date table in the slicer and visual

 

Also, refer

How to use two Date/Period slicers

https://youtu.be/WSeZr_-MiTg

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

i have a date slicer but my boss doesnt want a slicer he wants it immediatly in the dashboard to show so any help?

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.