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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Sum values from table A and B. But ignore data from table A when B has data in same period.

Good day,

 

I am struggling finding a solution to my problem. 

 

I have two tables. Table A and B. As per below. Table A is logged data from a SQL database, and Table B is manually inserted data to replace data in table A, whenever there is data logged with errors. 

 

Table A:

DateTagNoValue

01-04-2023

11000
02-04-20231500
03-04-20231600
05-05-20231400
06-05-20231500

 

Table B:

DateTagNoValue
01-04-202311100
   

 

I managed to use: 

 

Summed value = 

IF( SUM(Table B[Value]) > 0, SUM(Table B[Value]), 
    SUM (Table A [Value]) 
)

 

 

Using above measure, when selecting April, then total value is = 1100 (As per table B)

And when selecting May, total is = 900 (As per table A).

 

But when I select both April and May, then value is 1100, since the IF statement ignores data from table A.

 

Basically I need the measure to mainly sum values from table A, but when user manually inserts monthly corrected data in Table B, then values in Table A should be ignores. And I need it to sum value in the date range user has selected.

 

Thanks in advance!

 

Best,

Daniel 

1 ACCEPTED SOLUTION

Assuming that you have a date table linked to both A and B, you can use

Total =
SUMX (
    VALUES ( 'Date'[Year month] ),
    COALESCE (
        CALCULATE ( SUM ( 'Table B'[Value] ) ),
        CALCULATE ( SUM ( 'Table A'[Value] ) )
    )
)

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

Try

Total =
SUMX (
    'Table A',
    VAR BValue =
        LOOKUPVALUE (
            'Table B'[Value],
            'Table B'[Date], 'Table A'[Date],
            'Table B'[Tag no], 'Table A'[Tag no]
        )
    RETURN
        COALESCE ( BValue, 'Table A'[Value] )
)
Anonymous
Not applicable

Hi johnt75,

 

Thank you for your fast response.

 

If I am mistaken your solution will sort of replace a value in Table A if it exists in Table B.

Thing is, that in table a I collect data loggings every 10 min. And data logged in table B, is the whole month summarized in one logging. So the data in Table B represent total for a month, and I want that to replace the many rows in sameperiod in Table A. Hope it makes sense.

 

So basically, I am not interested in replacing a single value, But I want to replace the summed total with the new total inserted in Table B.

 

Thanks.

Assuming that you have a date table linked to both A and B, you can use

Total =
SUMX (
    VALUES ( 'Date'[Year month] ),
    COALESCE (
        CALCULATE ( SUM ( 'Table B'[Value] ) ),
        CALCULATE ( SUM ( 'Table A'[Value] ) )
    )
)
Anonymous
Not applicable

Hi again,

 

Worked perfectly - thanks a million 🙂

 

Have a great day ahead.

/Daniel

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.