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
Arianne
Regular Visitor

Subtotal of Weighted Scores with Filters

Hello, I'm trying to pull a data card value in my power bi report that represents the sum of weighted scores that should change based on filters. I created a basic example below to show the logic.

 

The first table shows the type of data I am working with in excel being pushed to power bi. In the second table, when I filter my data (remove supplier F), the total weighted score stays the same, when in reality, should total what it does in the third table (which modifies the subtotals according to filters). So essentially PBI is not taking the subtotals of my filters, but just the original subtotal regardless of filtering or not. Any idea how to do this in power bi?

 

So when I sum the "weighted score" value in power bi, I get a value that ignores all filtering and keeps the total from the entire dataset. At the moment, my datacard value in power bi is the sum of my weighted score field.

 

Image #1

 
 

table 1.png

 

Image #2 (filter out supplier f that does not modify totals)

table 2.png

 

Image #3 (filter out supplier f that does modify totals)

table 3.png

3 REPLIES 3
dedelman_clng
Community Champion
Community Champion

Hi @Arianne - this should work for what you're trying to do

 

Weight =
IF (
    HASONEVALUE ( Supplier[Supplier] ),  //Value for each row
    VAR __thisInv =
        CALCULATE ( SUM ( Supplier[Invoices] ) )
    VAR __allInv =
        CALCULATE ( SUM ( Supplier[Invoices] ), ALLSELECTED ( Supplier[Supplier] ) )
    RETURN
        DIVIDE ( __thisInv, __allInv, 0 ),
    1 //Value for "Total"
)

 

Weighted Score =
IF (
    HASONEVALUE ( Supplier[Supplier] ),     //Value for one row
     ( [Weight] * SUM ( Supplier[Score] ) ) / 2,
    SUMX (                                  //Value for total
        ALLSELECTED ( Supplier[Supplier] ),
        [Weight] * CALCULATE ( SUM ( Supplier[Score] ) )
    ) / 2
)

With all suppliers

 

2020-10-26 11_18_42-Window.png

 

With F filtered out

 

2020-10-26 11_19_12-Window.png

 

Hope this helps

David

Thank you David. It is not quite working completely. 

 

Perhaps I should mention that my dataset only includes the values for supplier, invoice, and score and that I need to calculate the weight and weighted score through my calculations. Below is the dataset that I am putting into PBI. Below is what I added as measures as per your suggestion but my PBI table is not depciting the right numbers (weight for supplier A should be 0.2 from 20/100, not 0.36).

 

Datset in PBI

SupplierInvoiceScore
A202
B52
C152
D350
E100
F152

 

Equations used in PBI:

 

Weight = 
IF (
    HASONEVALUE ( 'Table'[Supplier] ),  //Value for each row
    VAR __thisInv =
        CALCULATE ( SUM ( 'Table'[Invoice] ) )
    VAR __allInv =
        CALCULATE ( SUM ( 'Table'[Invoice] ), ALLSELECTED ( 'Table'[Supplier] ) )
    RETURN
        DIVIDE ( __thisInv, __allInv, 0 ),
    1 //Value for "Total"
)
Weighted Score = 
IF (
    HASONEVALUE ( 'Table'[Supplier] ),     //Value for one row
     ( [Weight] * SUM ( 'Table'[Score] ) ) / 2,
    SUMX (                                  //Value for total
        ALLSELECTED ( 'Table'[Supplier] ),
        [Weight] * CALCULATE ( SUM ('Table'[Score] ) )
    ) / 2
)

 

 

Result in PBI:

TABLE.PNG
 

Hello @Arianne -

Having Score in the visual and not having it summarized is what's causing the problem (so Now Power BI thinks it's a column not a value). This can be fixed in two ways:

1) Change the score to summarize via SUM in the drop-down list

2020-10-26 13_02_52-Window.png

2) Add REMOVEFILTERS(Supplier[Score]) to the Weight measure

Weight =
IF (
    HASONEVALUE ( Supplier[Supplier] ),    //Value for each row
    VAR __thisInv =
        CALCULATE ( SUM ( Supplier[Invoices] ) )
    VAR __allInv =
        CALCULATE (
            SUM ( Supplier[Invoices] ),
            ALLSELECTED ( Supplier[Supplier] ),
            REMOVEFILTERS ( Supplier[Score] )     // <----This is where it goes
        )
    RETURN
        DIVIDE ( __thisInv, __allInv, 0 ),
    1 //Value for "Total"
)

I hope this helps

David

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.