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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
SniperPro86
Frequent Visitor

DAX apply measure filter on the calculation

Hello
On the Contoso model I have a simple measure that calculate the amount of red product:

Red Sales = CALCULATE(
    [Amount],
    'Product'[Color] = "Red"
)

I want to create a measure that shows the Amount where the [Red Sales] is not blank without manually filtering the visual.
Below the expected result with filter on the visual :

SniperPro86_0-1682353886669.png

 

1 ACCEPTED SOLUTION

@SniperPro86 
Please try

MeasureTest3 =
SUMX (
    FILTER (
        VALUES ( Customer[Name] ),
        [Red Sales] <> BLANK ()
    ),
    [Amount]
)

Or 

MeasureTest4 =
SUMX (
    SUMMARIZE (
        FILTER (
            Sales,
            RELATED ( 'Product'[Color] ) = "Red"
        ),
        Customer[Name]
    ),
    [Amount]
)

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

@Greg_Deckler this is where CALCULATE fails to do its job.

tamerj1
Super User
Super User

Hi @SniperPro86 

please try

Red Sales =
CALCULATE ( [Amount], KEEPFILTERS ( 'Product'[Color] = "Red" ) )

Hi @tamerj1 
I don't want to calculate just the Amount of red product.
I want all the sales amount of the current context but just show the rows where there is a sales of a red product.
For exemple, I want all sales amount of customers who purchased at least one red product.
or all sales amount by years but just show the years where at least one sales of a red product happened.
I don't know if the requirement is clear.

@SniperPro86 
Please try

MeasureTest3 =
SUMX (
    FILTER (
        VALUES ( Customer[Name] ),
        [Red Sales] <> BLANK ()
    ),
    [Amount]
)

Or 

MeasureTest4 =
SUMX (
    SUMMARIZE (
        FILTER (
            Sales,
            RELATED ( 'Product'[Color] ) = "Red"
        ),
        Customer[Name]
    ),
    [Amount]
)

@tamerj1 
Thank you this is the elegant way I was searching for.

hi @SniperPro86 

try like:

Measure =
SUMX(
    CALCULATETABLE(
        VALUES(PRODUCT[Name]),
        FILTER(
            PRODUCT,
            PRODUCT[Color]="Red"
        )
     ),
    [Amount]
)

Hello @FreemanZ 
This is not working.
I wrote the measure below:

Measure Test 2 = 
var CustomerR = FILTER(VALUES(Customer[Name]), [Red Sales] <> 0)
Return
CALCULATE(
    [Amount],
    Customer[Name] in CustomerR
)

It is working fine when I do analyse by customer Name but give a wrong result when I analyse by date for exemple.

SniperPro86_0-1682411034354.png

 



 

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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