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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rbalza
Helper III
Helper III

Incorrect sum and average, display count and average

Hi PowerBi Superstars,

 

Hope you have a good midweek. I have table displaying TopN with its company name and type of jobs.

On the topN, it is displaying the incorrect sum and the rest of the sum of topN were blanks.

Also, when I try to display the count of each jobs and its average, it disregards the topN value. See attached sample file and the measures that I have used. https://www.dropbox.com/s/xszrjtxt9oo8k76/sampledata.pbix?dl=0

 

Thank you for this wonderful community. Hope I'll contribute as well as I progress.

 

Measure for Counting jobs

 

# of Jobs by Group Owner = SUMX(
    SUMMARIZE(FactFinalisedInvoicesDetailed, FactFinalisedInvoicesDetailed[Invoice Type],
        "Jobs", [Rank by Invoice Type] ),
        [Jobs] )

 

Displaying average of jobs

 

Average Total Invoice By Invoice Type = AVERAGEX( VALUES(FactFinalisedInvoicesDetailed[Invoice Type]), [Total Invoice] )

 

RankX measure

Rank by Invoice Type = 
RANKX(
    ALL(GroupedFinalisedInvoices[Group Owner]),
        CALCULATE( [Total Invoice],
            ALLSELECTED(FactFinalisedInvoicesDetailed[Invoice Type] ) ), , DESC )

topN measure

Total Invoice By Rank Group = 
SUMX(
    KEEPFILTERS(
        FILTER(
            ALLSELECTED( FactFinalisedInvoicesDetailed[Invoice Type] ), 
            COUNTROWS(
                FILTER(
                    'Customer Rank',
                    [Rank by Invoice Type] >= 'Customer Rank'[Min Rank]
                    && [Rank by Invoice Type] <= 'Customer Rank'[Max Rank] )
            ) > 0
        )
    ), [Total Invoice]
)

 

rbalza_1-1620177423772.png

Displaying count of jobs - where is the next topN?

rbalza_2-1620178123348.png

Displaying average of jobs - incorrect average and the next topN were missing

rbalza_3-1620178331561.png

 

 

 

 

 

1 ACCEPTED SOLUTION

2 REPLIES 2
AlexisOlson
Super User
Super User

Let's try starting from scratch.

 

Define [Total Invoice] as SUM ( FactFinalisedInvoicesDetailed[Invoice Total] ) and modify the ranking measure to return blanks if we're in the wrong ranking group.

Rank by Group Owner =
VAR MinRank = SELECTEDVALUE ( 'Customer Rank'[Min Rank] )
VAR MaxRank = SELECTEDVALUE ( 'Customer Rank'[Max Rank] )
VAR GroupRank =
    RANKX (
        ALL ( Customer[Group Owner] ),
        CALCULATE (
            [Total Invoice],
            ALLSELECTED ( FactFinalisedInvoicesDetailed[Invoice Type] )
        ),
        ,
        DESC
    )
RETURN
    IF (
        ISINSCOPE ( 'Customer Rank'[Customer Group] ),
        IF ( GroupRank >= MinRank && GroupRank <= MaxRank, GroupRank ),
        GroupRank
    )

 

This makes calculating the total easier.

Total Invoice by Rank Group =
SUMX (
    FILTER (
        VALUES ( Customer[Group Owner] ),
        NOT ISBLANK ( [Rank by Group Owner] )
    ),
    [Total Invoice]
)

 

Note that I'm using Customer[Group Owner] in the measures and visual instead of the column from GroupFinalisedInvoices. This is for simplicity to avoid having to think about the bi-directionally filtering many-to-many relationship.

Screenshot:

AlexisOlson_0-1620332621557.png

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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