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
Anonymous
Not applicable

DAX Measure filter (not in, or only in)

Hi

 

I have a simple datamodel with date, store, customer, product and a sales table binding them together.

I need to to do 3 mesaures that I am struggleing with.

 

1) The total sales of customers visiting Store A that have not bought anything in any other store.

2) The total sales of customers visiting Store B  that have not bought anything in any other store.

3) The total sales of customers visiting BOTH Store A and B

 

I need to measure this over the date dimension

 

Thanks

2 ACCEPTED SOLUTIONS

@Anonymous,

 

Check the following measures.

TotalSalesA =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        VALUES ( Sales[CustomerId] ),
        CALCULATE ( DISTINCTCOUNT ( Sales[StoreId] ) ) = 1
            && CALCULATE ( MAX ( Sales[StoreId] ) ) = 1
    )
)
TotalSalesAB =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        VALUES ( Sales[CustomerId] ),
        CALCULATE ( DISTINCTCOUNT ( Sales[StoreId] ), Sales[StoreId] IN { 1, 2 } )
            = 2
    )
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

The TotalSalesAB had a bug if a customer visits stores 1, 2 and 3 for example. So i changed it to this:

 

TotalSalesAB = 
CALCULATE (
    [TotalSales];
    FILTER (
        VALUES ( Sales[CustomerId] );
        CALCULATE ( DISTINCTCOUNT ( Sales[StoreId] ) ) = 2 && CALCULATE ( DISTINCTCOUNT ( Sales[StoreId] ); Sales[StoreId] <> 1 && Sales[StoreId] <> 2 ) = 0 
    )
)

 

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi @Anonymous,

 

Share a dataset and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Maybe try something like this?

 

[Only A Sales] =
CALCULATE (
    [Sales],
    FILTER (
        VALUES ( Sales[CustomerID] ),
        DISTINCTCOUNT ( Sales[StoreID] ) = 1
            && Sales[StoreID] = "A"
    )
)

You're simultaneously checking that the customer has only shopped in 1 store (distinctcount = 1) and that this store = A.

 

Change "A" to "B" for the 2nd measure.

 

For the 3rd measure, try this:

 

[A or B Sales] =
CALCULATE (
    [Sales],
    FILTER (
        VALUES ( Sales[CustomerID] ),
        DISTINCTCOUNT ( Sales[StoreID] ) = 2
            && Sales[StoreID] in {"A", "B"}
    )
)
Anonymous
Not applicable

Trying this out now in a simplified model.

 

2017-10-23 10_56_26 - Power BI Desktop.jpg

 

TotalSalesA = CALCULATE(
    [Sales],
    FILTER(
        VALUES(Sales[CustomerId]),
        DISTINCTCOUNT(Sales[StoreId]) = 1 && Sales[StoreId] = 1
    )
)

Getting error:

A single value for column 'StoreId' in table Sales cannot be determined. This can happen when a measure formula refers to a column that contains many values withour specifying an aggregation.

@Anonymous,

 

Check the following measures.

TotalSalesA =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        VALUES ( Sales[CustomerId] ),
        CALCULATE ( DISTINCTCOUNT ( Sales[StoreId] ) ) = 1
            && CALCULATE ( MAX ( Sales[StoreId] ) ) = 1
    )
)
TotalSalesAB =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        VALUES ( Sales[CustomerId] ),
        CALCULATE ( DISTINCTCOUNT ( Sales[StoreId] ), Sales[StoreId] IN { 1, 2 } )
            = 2
    )
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thats it!  Thankyou so much.

Anonymous
Not applicable

The TotalSalesAB had a bug if a customer visits stores 1, 2 and 3 for example. So i changed it to this:

 

TotalSalesAB = 
CALCULATE (
    [TotalSales];
    FILTER (
        VALUES ( Sales[CustomerId] );
        CALCULATE ( DISTINCTCOUNT ( Sales[StoreId] ) ) = 2 && CALCULATE ( DISTINCTCOUNT ( Sales[StoreId] ); Sales[StoreId] <> 1 && Sales[StoreId] <> 2 ) = 0 
    )
)

 

Anonymous
Not applicable

Thanks!

@Anonymous,

 

If your problem has been resolved, please help mark the useful reply as answer. Your contribution is highly appreciated.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the 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.