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

MAXX and MINX as filtering on measures in a direct query

Hi!

I'm trying to create a measure of 'Retained Customers' by counting customernumbers and filtering on min&max dates but I can't get it to work. Since I'm using a direct query, creating a new filter column is not an option.

 

This is among the formulas I tried to use:

 

# Retained Customers =

CALCULATE(

COUNT(f_Sales[CustomerSK]);

MAXX(f_Sales;[TransDt]<20161000); 

MINX (f_Sales;[TransDt]>20161000) 

)

 

 

 

Can someone help?

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @hannaegils,

 

1. What is your data source? It's still possible to create a column in my test -- SQL Server DB.MAXX and MINX as filtering on measures in a direct query .jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2. In your formula, the second and the third parameters will return errors.MAXX and MINX as filtering on measures in a direct query1.jpg

 

 

 

 

 

 

 

 

 

 

 

 

3. It will return nothing even if the formula is good. If we add a "=" to the formula, it will be very clear.

a) MAXX(f_Sales;[TransDt]<=20161000)    return 20161000

b) MINX (f_Sales;[TransDt]>=20161000)    return 20161000

a & b without "=" returns nothing.

 

4. What are the conditions exactly? Maybe you can try it like this:

# Retained Customers =
VAR maxValue =
    CALCULATE ( MAX ( f_Sales[TransDt] ); f_Sales[TransDt] < "Your Value 1" )
VAR minValue =
    CALCULATE ( MIN ( f_Sales[TransDt] ); f_Sales[TransDt] > "Your Value 2" )
RETURN
    CALCULATE (
        COUNT ( f_Sales[CustomerSK] );
        FILTER (
            ALL ( f_Sales );
            f_Sales[TransDt] > minValue
                && f_Sales[TransDt] < maxValue
        )
    )

Best Regards!

Dale

Community Support Team _ Dale
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

7 REPLIES 7
v-jiascu-msft
Employee
Employee

Hi @hannaegils,

 

Could you please mark the proper answer as solution or share the solution if it's convenient for you? That will be a big help to the others.

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

Hi @hannaegils,

 

1. What is your data source? It's still possible to create a column in my test -- SQL Server DB.MAXX and MINX as filtering on measures in a direct query .jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2. In your formula, the second and the third parameters will return errors.MAXX and MINX as filtering on measures in a direct query1.jpg

 

 

 

 

 

 

 

 

 

 

 

 

3. It will return nothing even if the formula is good. If we add a "=" to the formula, it will be very clear.

a) MAXX(f_Sales;[TransDt]<=20161000)    return 20161000

b) MINX (f_Sales;[TransDt]>=20161000)    return 20161000

a & b without "=" returns nothing.

 

4. What are the conditions exactly? Maybe you can try it like this:

# Retained Customers =
VAR maxValue =
    CALCULATE ( MAX ( f_Sales[TransDt] ); f_Sales[TransDt] < "Your Value 1" )
VAR minValue =
    CALCULATE ( MIN ( f_Sales[TransDt] ); f_Sales[TransDt] > "Your Value 2" )
RETURN
    CALCULATE (
        COUNT ( f_Sales[CustomerSK] );
        FILTER (
            ALL ( f_Sales );
            f_Sales[TransDt] > minValue
                && f_Sales[TransDt] < maxValue
        )
    )

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Worked as a charm! Thanks you so much 🙂

Ashish_Mathur
Super User
Super User

Hi,

 

What kind of a date is 20161000?  Share a dataset and show the expected result.


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

Hi,

The column "transdt" that contains the value 20161000 is formatted as a whole number in the dataset, although I have a connection to another table where I have the dates on different date formats.

/Hanna

Hi,

 

Share the link from where i can download your file.


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

Since you don't have access to our databases, a share of the file won't do any good here - will it?

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.