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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
o59393
Post Prodigy
Post Prodigy

How to combine lookup value with sumif

Hi all

 

I need to have the sumif from another table without duplicating the values.

 

In the example below a table called 'Template' has repeated the column Activity ID:

 

o59393_0-1706450202968.png

 

And another table called 'Summary' which should receive the sum of the hours of the table template without duplicates.

 

The column both tables have in column is 'merged'.

 

I am using the following dax:

Non Duplicate Hours Sum IF = 

CALCULATE (
    SUM(Template[Hours by Year]),
    FIRSTNONBLANK ( Template[Activity ID], 1 ),
    FILTER ( ALL ( Template ), Template[Merged] = 'Tech Collab'[Merged] )
)

 

However the result is not correct.

 

The result should be the sum of the non duplicated hours, which should be 1158 hours:

 

o59393_1-1706450398219.png

 

Any idea on how to fix my dax?

 

Thanks.

 

1 ACCEPTED SOLUTION

14 REPLIES 14
Ahmedx
Super User
Super User

pls try this

Screenshot_1.png

Hi @Ahmedx 

 

would it be possible to have it as a calculated column instead of a measure?

 

thank you!

pls try this

Screenshot_2.png

Hi @Ahmedx 

 

Thank you, almost there. The only thing is that the table summary should not have the activity id.

 

Table Summary should just be merged column and your calculated column. Something like this circled:

 

o59393_0-1706498716631.png

 

Would it be possible?

 

Thanks.

 

pls try this

Screenshot_1.png

Hi @Ahmedx 

 

When I use the formula in my real table I get a lot of duplicates for different Merged values in the table summary.

 

Can you please copy and paste the attached values below in your data source?

 

Test_Data.xlsx

 

The attach the xls contains the soution desired in the column 'hours'. Please notice I did the calculation manually just to represent the actual solution.

 

Thanks

 

pls try htis

Screenshot_1.png

and try this

Screenshot_2.png

Perfect @Ahmedx 

 

Thank you for your patience and help!

 

Regards.

By the way, the "DISTINCT" function is superfluous, you can remove it, it will not affect the result

az38
Community Champion
Community Champion

@o59393 

still not clear, sorry

for data sample like this

d_.png

 

I've got result like this

r.png


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

It's ok.

 

Can you please use these 2 tables:

 

Template:

Activity IDHours by YearMerged
8117DSTO
8117DSTO
8117DSTO
8117DSTO
8117DSTO
8117DSTO
8117DSTO
1386.1DSTO
1386.1DSTO
1386.1DSTO
1386.1DSTO
1386.1DSTO
1386.1DSTO
1386.1DSTO
1370.2DSTO
1370.2DSTO
7117DSTO
7117DSTO
6117DSTO
6117DSTO
1470.2DSTO
1470.2DSTO
9163.8DSTO
9163.8DSTO
9163.8DSTO
9163.8DSTO
9163.8DSTO
9163.8DSTO
10117DSTO
10117DSTO

 

And Summary:

 

Merged
DSTO

 

Then create the relationship of 1:M from Merged to Merged.

 

Finally the table merged is where you should add your calculated column.

 

Hope this helps.


Thanks!

az38
Community Champion
Community Champion

Hi @o59393 

 

it' s not clear your full model and task but you can try a measure

Non Duplicate Hours Sum IF = 
var _t = DISTINCT(Template[Hours By Year])
RETURN
CALCULATE(SUMX(_t, [Hours By Year]))

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hi @az38 

 

Thanks for your reply.

 

Can Activity ID be added to your dax? This is because for example 2 different activivities could have the same hours (for example 10 and 10 hours).

 

With your dax it would only sum 10, however it should be 20 as the activitiy Id's are different.

 

In my dax I also put the lookup function because the table Summary should lookup the sumif from the table template.

 

The table summary that I already exists should have the measure:

 

MergedNon Duplicate Hours Sum IF
DSTO1158.3

 

 Hope Im more clear.

 

Thanks.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors