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
RainyClouds
New Member

Need help with DAX for percentage of filtered total with a twist

Hello all,

 

I'm trying to calculate a couple of measures in DAX using this dummy set of data from the table below (I cannot provide real data due to the nature of the project):

SalesPersonDatePaymentTypeLocationCategoryTransactionFlagAmount
Daisy11-JanCashMetroDongle010
Daisy11-JanCashRegionalWidget 15
Daisy11-JanCardMetroWidget1100
Daisy10-JanCashMetroWidget 12
Daisy10-JanCashRegionalWidget117
Daisy10-JanCardMetroDongle0120
Dean11-JanCashMetroDongle011
Dean11-JanCashRegionalWidget016
Dean11-JanCardMetroWidget0110
Dean10-JanCashMetroWidget013
Dean10-JanCashRegionalWidget018
Dean10-JanCardMetroDongle0130
Gillian11-JanCashMetroDongle09
Gillian11-JanCashRegionalWidget014
Gillian11-JanCardMetroWidget190
Gillian10-JanCashMetroWidget018
Gillian10-JanCashRegionalWidget019
Gillian10-JanCardMetroDongle080
Gibbo11-JanCashMetroDongle020
Gibbo11-JanCashRegionalWidget021
Gibbo11-JanCardMetroWidget 140
Gibbo10-JanCashMetroWidget030
Gibbo10-JanCashRegionalWidget08
Gibbo10-JanCardMetroDongle 105

*Note that in the table above, the TransactionFlag can have values of 1 (for true), 0 (for false), or blank (for not applicable).

 

The two measures are for Flagged Transaction Amount (those where TransactionFlag = 1) as a percentage of a SalesPerson's total Amounts; and then Flagged Transaction Amount as a percentage of all SalesPerson's total amounts who have a flagged transaction. I will also want to be able to slice the report by all dimensions. It is important that all of a SalesPerson's amounts are included in the total if and only if they have a flagged transaction in whatever slice has been selected.

 

So effectively I want to be able to get to a table like this:

SalesPerson  Date  PaymentType  Location  Category  Amount  Flagged Amount as a % of SalesPerson Total Amount  Flagged Amount as a % of All SalesPerson with FlaggedTransaction Total Amount  
Daisy11-JanCardMetroWidget10080.0042.02
Daisy10-JanCashRegionalWidget1711.4111.41
Gillian11-JanCardMetroWidget9079.65

37.82

 

 

And like this:

SalesPerson  PaymentType  Category  Amount  Flagged Amount as a % of SalesPerson Total Amount  Flagged Amount as a % of All SalesPerson with FlaggedTransaction Total Amount  
DaisyCardWidget11779.5943.66
GillianCardWidget9074.3833.58

 

Can anyone help me with the DAX for these measures? I'm not really even sure where to start. Thanks!

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @RainyClouds,

 

You can use following measures to achieve your requirement, it will dynamic changes based on category fields:

% of SalePerson =
DIVIDE (
    SUM ( Sales[Amount] ),
    CALCULATE (
        SUM ( Sales[Amount] ),
        ALLSELECTED ( Sales ),
        VALUES ( Sales[SalesPerson] )
    ),
    -1
)

% of ALL SalePerson =
DIVIDE (
    SUM ( Sales[Amount] ),
    CALCULATE ( SUM ( Sales[Amount] ), ALLSELECTED ( Sales ) ),
    -1
)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @RainyClouds,

 

You can use following measures to achieve your requirement, it will dynamic changes based on category fields:

% of SalePerson =
DIVIDE (
    SUM ( Sales[Amount] ),
    CALCULATE (
        SUM ( Sales[Amount] ),
        ALLSELECTED ( Sales ),
        VALUES ( Sales[SalesPerson] )
    ),
    -1
)

% of ALL SalePerson =
DIVIDE (
    SUM ( Sales[Amount] ),
    CALCULATE ( SUM ( Sales[Amount] ), ALLSELECTED ( Sales ) ),
    -1
)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.