Customers who bought and not bought some product in last 90 days

时间:2018-08-22 13:42:31

标签: ssas powerbi dax powerpivot

I need a dax measure which shows me which customers bought products B and C in last 90 days.

And another one which shows me those whose bought products B and C in last 90 days.

(based in my filter date context)

Below is like it should be:

Image

Can someone help me?

Here is a sample data if needed:

FactSales

KeyDate KeyCustomer KeyProduct  Total
1   1   1   12,9
1   2   2   13
1   3   1   156,4
1   4   1   564,8
2   1   1   894,8
2   2   1   56,5
3   1   2   564,85
3   2   3   564,8
4   1   1   1325,6
4   2   1   132,3

Customer

KeyCustomer Name
1   Jean
2   Mari
3   Lisa
4   Julian
5   Jhonny

Calendar

KeyDate Date
1   01/01/2018
2   02/01/2018
3   01/05/2018
4   01/08/2018

Product

KeyProduct  Product
1   A
2   B
3   C

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

IfBought = IF(
              COUNTROWS(
                  FILTER(FactSales,
                      RELATED('Product'[Product]) IN {"B", "C"} &&
                      RELATED('Calendar'[Date]) > TODAY() - 90)
                  ) > 0,
              1, 0)

请注意,尽管从今天起5月1日比今天早了90天,所以除非您将90更改为114或更高,否则您不会得到想要的结果。