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

Filter sales on dates where every customer has a recorded purchase

@Amit 

 

Hi,

 

I have a standard model, with a transaction table, a date table and a customer table (10 customers).

 

What I need is to calculate sales, but only for days where every customer have a recorded purchase.

 

That means that if I have no customers selected in my slicer, only sales for days where all 10 customers made a purchase should be filtered, if I select 2 customers in my slicer only sales for days where both these 2 customers made a purchase should be filtered, and so on.

 

This needs to be done dynamic, so I have so far created the following measures:

 

  1. Sales = SUM ( TransactionTable[Value] )
  2. Number of Customers Filtered = COUNTROWS ( VALUES ( CustomerTable[Customer] ) )
  3. Number of Customers in TransactionTable = COUNTROWS ( VALUES ( CustomerTable[Customer] ) )
  4.  Sales Filtered = CALCULATE(
    [Sales] ,
    FILTER(
    VALUES( '01_FACT_Forecast_SpotPrice'[ValueDateCET] ) ,
    [Number of Customers in TransactionTable] = [Number of Customers Filtered]
    )
    )

 

This provides me with the following result:

 

Preben_2-1641372707787.png

 

So far so good, Sales Filtered excludes datetimes where there is only 1 customer (I have choosen 2 customers in this example).

 

The problem emerges when I want to add customer as a dimension. Then I only get the total, no split on individual customers:

 

Preben_1-1641372692238.png

 

Clearly, my approach is not correct, so any help would be much appreciated

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I found a solution:

 

  1. Sales = SUM ( TransactionTable[Value] )
  2. Number of Customers Filtered = CALCULATE(
    COUNTROWS (
    VALUES ( CustomerTable[Customer] )
    ) ,
    ALLSELECTED( CustomerTable[Customer] )
    )
  3. Number of Customers in TransactionTable = CALCULATE(
    COUNTROWS (
    VALUES ( TransactionTable[Customer] )
    ) ,
    ALLSELECTED( CustomerTable[Customer] )
    )
  4.  Sales Filtered = CALCULATE(
    [Sales] ,
    FILTER(
    VALUES( Date[Date] ) ,
    [Number of Customers in TransactionTable] = [Number of Customers Filtered]
    )
    )
     
    Thank you to everyone for posting

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

I found a solution:

 

  1. Sales = SUM ( TransactionTable[Value] )
  2. Number of Customers Filtered = CALCULATE(
    COUNTROWS (
    VALUES ( CustomerTable[Customer] )
    ) ,
    ALLSELECTED( CustomerTable[Customer] )
    )
  3. Number of Customers in TransactionTable = CALCULATE(
    COUNTROWS (
    VALUES ( TransactionTable[Customer] )
    ) ,
    ALLSELECTED( CustomerTable[Customer] )
    )
  4.  Sales Filtered = CALCULATE(
    [Sales] ,
    FILTER(
    VALUES( Date[Date] ) ,
    [Number of Customers in TransactionTable] = [Number of Customers Filtered]
    )
    )
     
    Thank you to everyone for posting
amitchandak
Super User
Super User

@Anonymous , Try measures like

 

Sales = SUM ( TransactionTable[Value] )

 

Number of Customers Filtered = calculate(COUNTROWS ( VALUES ( CustomerTable[Customer] ) ), all(CustomerTable) )

Sales Customer Date= calculate(countx(filter(values(CustomerTable[Customer]), [Sales]>0), [Customer]), allexcept(TransactionTable,CustomerTable[Customer], 'Date'[Date]))

Number of Customers in TransactionTable = countx(filter(addcolumns(summarize(TransactionTable,CustomerTable[Customer], 'Date'[Date]) , "_1", [Sales] ,
[_2], [Sales Customer Date]), [_2] = [Number of Customers Filtered]),[_1])

Anonymous
Not applicable

Hi @amitchandak , and thank you for a hasty reply.

 

The solution did not work unfortunetly. This was the result:

 

Preben_0-1641376928441.png

 

  1. I could not use the ALL function in Number of Customers Filtered (I would only have recieved 10 as a result, not 2 as was filtered).
  2. Sales Customer Date seems to generate the exact same result as Number of Customers Filtered
  3. Number of Customers in Transaction Table seems to generate the exact same result as previously

I think the problem lies with my measure "Sales Filtered", which does not seem able to filter Sales correctly in response to dates where Customers Filtered and Number of Customers in Transaction Table is the same (2 in my example, since I filtered on 2 customers).

 

What do you think?

@Anonymous , Got lost in this one, we should not include customer in 2nd one

Sales Customer Date= calculate(countx(filter(values(CustomerTable[Customer]), [Sales]>0), [Customer]), allexcept(Date, 'Date'[Date]))

 

So, means distinct customer on that date

 

or

Sales Customer Date= calculate(countdistinct(CustomerTable[Customer]), allexcept(Date, 'Date'[Date]))

 

I was using all in first one to get 10, So that we can check for each date we have only 10 customer 

 

Thrid one we can also try like

 

Number of Customers in TransactionTable = countx(Values('Date'[Date]) ,
If( [Sales Customer Date] = [Number of Customers Filtered], [Sales], blank()) )

Anonymous
Not applicable

Hi @amitchandak ,

 

Still no luck.

 

The problem is that the measure number 4 (Sales Filtered), which is the measure that I need to find the sales on dates where all customer have made a purchase, are able to filter in a "total context", but not in a "subtotal context".

Preben_0-1641391503021.png

 

The matrix shows that values for the second customer is still apperent, even though they are filtered out in the total context. These are the values I need to remove/filter out

@Anonymous  provide a sample pbix

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.

Top Solution Authors