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
evolu6ion
Frequent Visitor

Measures using measures as filters

Hello everyone,

 

Today, I am stuck at making a measure that has to deal with filters based on another measure result.

 

Here is a sample of my data and the problem that is appearing:

2019-05-21 14_32_47-Courbe des actifs - Power BI Desktop.png

 

In the matrix, I have 3 different customers and their purchases behavior. In the wide red rectangle, you can see that as long as their latest purchase date is farther than 24 months from the end of the current row month, the customer should not be calculated with the 'Nb of customers 24 months' measure. When this measure is in such matrix, it behaves as it should. But whenever I remove the 'Customer number' column, I do not manage to get the desired result (see (1) on the image above).

 

The desired result in this aggregated table would be:

YEARMONTHWRONG Nb of cust 24 monthDesired Result
2018March32
2018April32
2018May32
2018June32
2018July31
2018August31
2018September31
2018October31
2018November31

 

Here is the code used for the aformentioned measures:

TEMP Nb cust 24 month = 
COUNTA(Customer[Customer Number])

Nb cust 24 month = 
IF(
    [Nb of months since last purchase] >= 0 && [Nb of months since last purchase] <= 24;
    CALCULATE(
        [TEMP Nb cust 24 month];
        FILTER(
            ALL(Calendar[Date]);
            Calendar[Date] <= MAX(Calendar[Date])
        )
    );
    BLANK()
)

TEST Nb cust 24 month = 
VAR Cust = 
[Nb cust 24 month]
RETURN
CALCULATE(
    COUNTA(Customer[Customer Number]);
    FILTER(
        Sales;
        Cust >0
    )
)


The data model is a simple star schema with a Fact Sales table and 2 dimension tables (Customer and Calendar, with the Calendar table being linked to the fact with 'Sales date').

 

Your help would be much appreciated.

 

Thanks in advance.

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @evolu6ion 

It is invaild of this measure.

TEST Nb cust 24 month = 
VAR Cust = 
[Nb cust 24 month]
RETURN
CALCULATE(
    COUNTA(Customer[Customer Number]);
    FILTER(
        Sales;
        Cust >0
    )
)

 

Since the table doesn't contain [Customer Number] column,don't use [Customer Number] column in this measure, try to use other column.

Or add [Customer Number] column in the table visual.

 

Best Regards
Maggie

 

 

 

View solution in original post

1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @evolu6ion 

It is invaild of this measure.

TEST Nb cust 24 month = 
VAR Cust = 
[Nb cust 24 month]
RETURN
CALCULATE(
    COUNTA(Customer[Customer Number]);
    FILTER(
        Sales;
        Cust >0
    )
)

 

Since the table doesn't contain [Customer Number] column,don't use [Customer Number] column in this measure, try to use other column.

Or add [Customer Number] column in the table visual.

 

Best Regards
Maggie

 

 

 

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.