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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate duplicate data

Here are my data:

 

CompanySiteManaged by Company A?Total kWh
A1 100
A2 200
A3 150
A4 300
A5 70
B2Yes200
B3Yes150
B5Yes70
B6No275

 

Company A and B are under Group X. I would like to calculate the sum of kWh. Group X can view all data from company A and B, but company A and B can only view their own data only (I'm using row-level security here). I'm having problem when calculating sum of kWh for Group level because this will cause duplication. 

 

My desired result would be:

Sum of kWh for Company A = 820

Sum of kWh for Company B = 695

Sum of kWh for Group X = 1,095

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Create 3 measures as below:

 

Sum of kWh for Company A = SUMX(FILTER(ALL('Table'),'Table'[Company]="A"),'Table'[Total kWh])
Sum of kWh for Company B = SUMX(FILTER(ALL('Table'),'Table'[Company]="B"),'Table'[Total kWh]) 
Sum of kWh for Group X = SUMX(ALL('Table'),'Table'[Total kWh])-SUMX(FILTER(ALL('Table'),'Table'[Company]="B"&&'Table'[Managed by Company A?]="Yes"),'Table'[Total kWh])

 

And you will see:

Annotation 2020-07-07 144441.png

For the related .pbix file,pls click here.

 

 
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@Anonymous , Try a measure like

sumx(Table,distinctcount(Table[Total kWh]))

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

@amitchandak I don't think that's correct because you're using DISTINCTCOUNT 😅

@Anonymous , oops ,

See if this can work

sumx(values(Table[Total kWh]),Table[Total kWh])
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

@amitchandak It's working, but I realised that you're using VALUES. This one only works when the column has distinct values, right? It's because when I changed the data a little bit, I did not get my desired result. You can try with this new data instead:

 

CompanySiteManaged by Company A?Total kWh
A1 100
A2 200
A3 150
A4 300
A5 150
B2Yes200
B3Yes150
B5Yes150
B6No275

 

For this new data, my desired result would be:

Sum of kWh for Company A = 900

Sum of kWh for Company B = 775

Sum of kWh for Group X = 1,175

Anonymous
Not applicable

Hi @Anonymous ,

 

Create 3 measures as below:

 

Sum of kWh for Company A = SUMX(FILTER(ALL('Table'),'Table'[Company]="A"),'Table'[Total kWh])
Sum of kWh for Company B = SUMX(FILTER(ALL('Table'),'Table'[Company]="B"),'Table'[Total kWh]) 
Sum of kWh for Group X = SUMX(ALL('Table'),'Table'[Total kWh])-SUMX(FILTER(ALL('Table'),'Table'[Company]="B"&&'Table'[Managed by Company A?]="Yes"),'Table'[Total kWh])

 

And you will see:

Annotation 2020-07-07 144441.png

For the related .pbix file,pls click here.

 

 
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Anonymous
Not applicable

Hi @Anonymous,

Thank you for your help!

 

I'm just curious, is it possible to get the result that I want without using [Managed by Company A?] column?

Hi @Anonymous ,

 

If dont use [Managed by Company A?] column ,how to know that which value needs to be removed?

 

 
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors