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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
DmitryAD7
Helper I
Helper I

KEEPFILTERS need help

Hello community.

 

I need help with a measure. With two conditions:

- the customer ID "5335794105" must be excluding only from AA Department (regardless of any filters)

- if only 2 companies (fourth and fifth) are selected, the volume of one of them must be multiplied. Thanks @talespin with the measure (measure: 2. Sales with Condition).

I need help, because I can’t combine both conditions in one measure.

link to the file.

 

Thanks.

1 ACCEPTED SOLUTION

hi @DmitryAD7 

 

Please use this measure.

 

Change the data type for Value column from test to number.

You have interaction disabled between Company Slicer and the table visual.

 

Test =
VAR _count_check =
    DISTINCTCOUNT ( 'Dataset'[Company] )
VAR _exch_rate = 5
VAR _c1_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        'Dataset'[Company] = "Fifth Company",
        KEEPFILTERS(NOT ( 'Customers'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" ) )
    )
VAR _c1_value_mp = _c1_value * _exch_rate
VAR _c2_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        'Dataset'[Company] = "Fourth Company",
        KEEPFILTERS(NOT ( 'Customers'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" ) )
    )
VAR _default_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        KEEPFILTERS ( NOT ( 'Customers'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" ) )
    )
VAR Result =
    IF (
        CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fourth Company" )
            && CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fifth Company" )
            && _count_check = 2,
        _c1_value_mp + _c2_value,
        _default_value
    )
RETURN
    Result

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

Hi, @DmitryAD7 

Unfortunately, due to the company's privacy policy, the link you shared doesn't open in my work environment, you can use GoogleDrive to share your pbix file (please note that when sharing, please don't set up a login to your Google account to access the link)

 

vyaningymsft_0-1709529260696.png

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hello. Please try this link.

Anonymous
Not applicable

Hi, @DmitryAD7 

I can successfully open the link you shared, but there are still areas of confusion about your question:
1. what is the final result you want to achieve after filtering the data, a data table?
2. if you select only 2 companies (4th and 5th), you have to multiply the transaction volume of one of the companies. Here which two companies are multiplied or one of them is multiplied with other data, you need to describe your requirement in detail (use snapshot if you can)

 

Best Regards,
Yang
Community Support Team

For the first condition (with customer exclusion):
if one department is selected, totals are correct:

DmitryAD7_0-1709717761330.png

when two or more departments are selected, totals are incorrect:

DmitryAD7_1-1709717852824.png

 

Anonymous
Not applicable

Hi, @DmitryAD7 

 

Based on your description, I have created some measures to achieve the effect you are looking for. Following picture shows the effect of the display.

 

vyaningymsft_0-1709798771351.png

Measure:

1. Sell-out =

VAR _customer_excl =

    CALCULATE (

        SUM ( 'Dataset'[Value] ),

        FILTER ( 'Dataset', 'Dataset'[Customer ID] <> "5335794105" )

    )

VAR _default_value =

    CALCULATE ( SUM ( 'Dataset'[Value] ) )

VAR _dep =

    SELECTEDVALUE ( 'Dataset'[Departmet] )

VAR _ExceptDepartment = "AA Department"

VAR Result =

    IF (

        _ExceptDepartment IN ALLSELECTED ( 'Dataset'[Departmet] ),

        _customer_excl,

        _default_value

    )

RETURN

    Result


Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

 

 

Hello @Anonymous

 

Unfortunately, the results are incorrect. According to the condition, value should be excluded only for the Customer ID = "5335794105" in AA Department. Your DAX excluded Customer ID = "5335794105" from all deparments.

DmitryAD7_0-1709804233548.jpegDmitryAD7_1-1709804250247.jpeg

The expected total result (for all departments) is 57500 (59000-1500), for AA + BB is 11500 (13000-1500). Cause the Customer ID = "5335794105value for AA Department is 1500.

hi @DmitryAD7 

 

Please try this measure.

 

Test =

VAR _count_check = DISTINCTCOUNT ( 'Dataset'[Company] )
VAR _exch_rate = 5
VAR _c1_value =
    CALCULATE (
        SUM ('Dataset'[Value]),        
        'Dataset'[Company] = "Fifth Company",
        NOT('Dataset'[Departmet] = "AA Department" && 'Dataset'[Customer ID] = "5335794105")
    )
VAR _c1_value_mp = _c1_value * _exch_rate
VAR _c2_value =
    CALCULATE (
        SUM ('Dataset'[Value]),
        'Dataset'[Company] = "Fourth Company",
        NOT('Dataset'[Departmet] = "AA Department" && 'Dataset'[Customer ID] = "5335794105")
    )

VAR _default_value = CALCULATE(SUM ('Dataset'[Value]), KEEPFILTERS(NOT('Dataset'[Departmet] = "AA Department" && 'Dataset'[Customer ID] = "5335794105")) )

VAR Result =
    IF (
        CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fourth Company" ) && CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fifth Company" ) && _count_check = 2,
        _c1_value_mp + _c2_value,
        _default_value
    )

RETURN Result
 
talespin_0-1709808350525.png

 

talespin_1-1709808363034.pngtalespin_2-1709808378319.png

 

Hi @talespin ,

 

thanks a lot for your help, but I apologize for the incorrect info, in my work model Customer ID column is in another table and has a many-to-one relationship to the Dataset table. Link to correct file.

DmitryAD7_0-1709836169744.jpeg

Please help to correct the code.

Test = 
VAR _count_check =
    DISTINCTCOUNT ( 'Dataset'[Company] )
VAR _exch_rate = 5
VAR _c1_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        'Dataset'[Company] = "Fifth Company",
        NOT ( 'Dataset'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" )
    )
VAR _c1_value_mp = _c1_value * _exch_rate
VAR _c2_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        'Dataset'[Company] = "Fourth Company",
        NOT ( 'Dataset'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" )
    )
VAR _default_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        KEEPFILTERS ( NOT ( 'Dataset'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" ) )
    )
VAR Result =
    IF (
        CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fourth Company" )
            && CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fifth Company" )
            && _count_check = 2,
        _c1_value_mp + _c2_value,
        _default_value
    )
RETURN
    Result

 

hi @DmitryAD7 

 

Please use this measure.

 

Change the data type for Value column from test to number.

You have interaction disabled between Company Slicer and the table visual.

 

Test =
VAR _count_check =
    DISTINCTCOUNT ( 'Dataset'[Company] )
VAR _exch_rate = 5
VAR _c1_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        'Dataset'[Company] = "Fifth Company",
        KEEPFILTERS(NOT ( 'Customers'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" ) )
    )
VAR _c1_value_mp = _c1_value * _exch_rate
VAR _c2_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        'Dataset'[Company] = "Fourth Company",
        KEEPFILTERS(NOT ( 'Customers'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" ) )
    )
VAR _default_value =
    CALCULATE (
        SUM ( 'Customers'[Value] ),
        KEEPFILTERS ( NOT ( 'Customers'[Department] = "AA Department"
            && 'Customers'[Customer ID] = "5335794105" ) )
    )
VAR Result =
    IF (
        CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fourth Company" )
            && CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fifth Company" )
            && _count_check = 2,
        _c1_value_mp + _c2_value,
        _default_value
    )
RETURN
    Result

Hi @talespin . Thank you for your help. All works perfect!

hi @DmitryAD7 

 

You're welcome.

Hello, thank you for your question and time.

 

In general I need to calculate two conditions in one measure.


First condition:

Always (regardless of filters), only for one department “AA Department” customer ID "5335794105" was excluded from the total results.
How this measure is currently calculated:
Sell-out =
VAR_customer_excl =
CALCULATE (
[Base Measure],
KEEPFILTERS ( NOT ( 'Dataset'[Customer ID] = { "5335794105" } ) )
)
VAR_dep =
SELECTEDVALUE('Dataset'[Departmet])
VAR_default_value = [Base Measure]
VAR Result =
IF ( _dep = "AA Department", _customer_excl, _default_value )
RETURN
Result

But there is an error here, since when selecting several departments, total ignores the condition for excluding the customer ID "5335794105" from the “AA Department”.

 

Second condition:

If only 2 companies "Fourth Company" and "Fifth Company" were selected at the same time, the volume of "Fifth Company" was multiplied by ExchRate (VAR _exch_rate = 5). Under other conditions in the slicer, the multiplier is not used.
How this measure is currently calculated (this measure works fine.):

Sales with Condition =
VAR_count_check =
DISTINCTCOUNT('Dataset'[Company])
VAR_exch_rate = 5
VAR_c1_value =
CALCULATE (
[Base Measure],
REMOVEFILTERS('Dataset'[Company]),
'Dataset'[Company] = "Fifth Company"
)
VAR _c1_value_mp = _c1_value * _exch_rate
VAR_c2_value =
CALCULATE (
[Base Measure],
REMOVEFILTERS('Dataset'[Company]),
'Dataset'[Company] = "Fourth Company"
)
VAR_default_value =
CALCULATE (
[Base Measure],
REMOVEFILTERS('Dataset'[Company]),
VALUES ( 'Dataset'[Company] )
)
VAR Result =
IF (
CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fourth Company" )
&& CONTAINSROW ( VALUES ( 'Dataset'[Company] ), "Fifth Company" )
&& _count_check = 2,
_c1_value_mp + _c2_value,
_default_value
)
RETURN
Result

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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