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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.  

AiolosZhao
Memorable Member
Memorable Member

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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])

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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