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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jaynesa
Helper II
Helper II

Calculating a total while ignoring duplicate values in a column

I'm currently loading and transforming my table "Payroll" into Power Query.  And I want to be able calculate a true annual total for the Payroll, without double counting.  The data load comes out like this:

How the data is being brought into Power QueryHow the data is being brought into Power Query

I want to be able to calculate a true annual total for 2019, resulting in Q1+Q2+Q3+Q4, or rather 5000+7500+4000+6000 = 22500.  How can I achieve this in the column "Annual Payroll Total"?  I've been racking my brain on this all  night, please help!!!

 

What I ultimately want to be able to doWhat I ultimately want to be able to do

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

Drag the first 4 fields to a Table visual and write these measures

Average location payroll = average(Data[Total location payroll])

Annual Payroll total = SUMX(Data,[Average location payroll])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yingjl
Community Support
Community Support

Hi @jaynesa ,

I have added some rows data about 2020 like this:

Payroll table.png

Create the following measure:

Annual Payroll Total =
SUMX (
    FILTER (
        SUMMARIZE (
            ALL ( 'Payroll' ),
            'Payroll'[Organization],
            'Payroll'[Location],
            'Payroll'[Category],
            'Payroll'[Year],
            'Payroll'[Qtr],
            "Annual Payroll Total", MAX ( 'Payroll'[Total Location Payroll] )
        ),
        [Year] = SELECTEDVALUE ( Payroll[Year] )
    ),
    [Annual Payroll Total]
)

You will get your expected output:

payroll result.png

Here is the sample file that hopes to help you, please try it: Calculating a total while ignoring duplicate values in a column.pbix 

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

This is extremely good... but why can't I get it to work in a column?  And only a measure?  I really need it in the column.  Any suggestions?

Hi @jaynesa ,

If you want to create a calculated column, you can try this formula:

Total =
VAR tab =
    FILTER (
        SUMMARIZE (
            ALL ( 'Payroll' ),
            'Payroll'[Organization],
            'Payroll'[Location],
            'Payroll'[Category],
            'Payroll'[Year],
            'Payroll'[Qtr],
            'Payroll'[Total Location Payroll]
        ),
        [Year] = EARLIER ( Payroll[Year] )
    )
RETURN
    SUMX ( tab, [Total Location Payroll] )

You will get the expected result like this:

colum result.png

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

It worked!!  THANKYOU!!!

Yingjie Li, I'm almost there.  Question, in the Section that you have:  [Year] = Earlier (Payroll[Year]) 

Can I add more filters than just the year?  For example, if I wanted to have both Year and Location, what would that syntex be?  I've tried a few times but it keeps telling me that the syntax is wrong.  

Anonymous
Not applicable

Hi @jaynesa ,

 

Please try to use the below measure:

Calculating a total while ignoring duplicate values in a column.PNG

 

KEY = 'Table'[Ora] & 'Table'[Loc] & 'Table'[CAT] & 'Table'[Year] & 'Table'[QTR]

Measure 3 = SUMX(SUMMARIZE(ALL('Table'),'Table'[KEY],"annual",DIVIDE(SUM('Table'[payroll]),COUNTA('Table'[KEY]),0)),[annual])

 

KEY is a calculated column.

 

Aiolos Zhao

This is getting me close.  So, let's say the year changes, or some other column like "Category".  For exampe, if the year changes to 2020, how can I make sure the new column calc only calc's 2020?  How will it know to not include 2019?

amitchandak
Super User
Super User

@jaynesa 

Try something like this

sumx(Summarize(Table,Table[organization],table[location], Table[Category] ,Table[year],Table[Qtr],"_1",max(Table[Total location Payroll])),[_1])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

So, let's say the year changes, or some other column like "Category".  For exampe, if the year changes to 2020, how can I make sure the new column calc only calc's 2020?  How will it know to not include 2019?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.