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
mdrammeh
Helper III
Helper III

How can I remove duplicate values from a single column with multiple year refrenced

I have a dataset with millions of records for multiple “CD_WR”(Column). For each CD_WR, I want to count the “Total Miles” (Column D) once to avoid duplicating the total number of miles. How should I approach this in Power BI or Power Query?

 

How can I count the miles once? Or divide by the count of miles?How can I count the miles once? Or divide by the count of miles?

4 REPLIES 4
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @mdrammeh,

The picture displays the expected result, right? If it is, in Power Query Editor, please select the CD_WR and DT_BUDGET_YR columns, right click->remove the duplicate value, it will remove the duplicates according to CD_WR and DT_BUDGET_YR columns. For instance, I select the Date and area fields->remove duplicates, it will return the expected result shown in second screenshot.

 

1.PNG

 

Capture1.PNG

After remove the duplicate, click the Apply&Close, you will get the distinct tables, then you create a calclated column using the formula below.

Sum of Total miles=CALCULATE(SUM(Table[Total Miles]),ALLEXCEPT(Table, Table[CD_WR]))


If this is not what you want, please post the sample data for further analysis.

Best Regards,
Angelia

Hi Angelia,

 

So when you look at the Sum of Miles column at the very end, notice that the same miles are duplicated for each year. What I want to do is to either average out the sub-totals so that each year represents a portion of the miles or make it such that the miles will only be counted once. 

 

For example, let's say you have 9 miles of construction work to be completed in three years (2016, 2017, and 2018). For each year, you want to show that only 3 miles of work have been constructed. But your data shows that 9 miles for each year of work completed. How would you organize your data such that it would only show the average miles of the total (9 miles) to be spread out for each year in the order shown above? 

 

Thank!

Mustapha

You haven't shared your data structure so it is hard to give you a precise answer. However looking at the output you posted, I could guess at the following. 

 

Write these measure

 

Total miles = Sum(table[total miles])

total years = calculate(distinctcount(table[cd_wr]),all(table[budget year]))

Avg Miles = divide([total miles],[total years])

 

the secret sauce is that total years always returns the total regardless of a budget year filter. 

 

Here is some dreading for you 

http://exceleratorbi.com.au/best-practices-power-pivot-power-query-power-bi/

http://exceleratorbi.com.au/create-lookup-table-power-pivot/



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Hi Angelia,

 

So when you look at the Sum of Miles column at the very end, notice that the same miles are duplicated for each year. What I want to do is to either average out the sub-totals so that each year represents a portion of the miles or make it such that the miles will only be counted once. 

 

For example, let's say you have 9 miles of construction work to be completed in three years (2016, 2017, and 2018). For each year, you want to show that only 3 miles of work have been constructed. But your data shows that 9 miles for each year of work completed. How would you organize your data such that it would only show the average miles of the total (9 miles) to be spread out for each year in the order shown above? 

 

Thank!

Mustapha

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.