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
Asantos2020
Advocate II
Advocate II

Firstdate or Min not working when trying to ignore filters

Hello there,

 

The DAX measure below is not working:

FirstPurchase = CALCULATE(FIRSTDATE(SalesFactTable[Date]);ALL('Calendário'[Date]))
 
I need to use it on a table visual, as follows:
 
Customer   Last Purchase   Purchase Cycle    First Purchase
A                  09/29/2019               4                09/25/2019
B                  09/15/2019              15               09/01/2019
 
The data above is from a SalesFactTable and I have a Calendar Table on a slicer and which filters the SalesFactTable.
 
I've tried so many possibilities and some give me 12/31/1899.
 
Thanks in advance!
1 ACCEPTED SOLUTION

Hello @MFelix ,

 

Here is how I've fixed it:

Primeira Compra = CALCULATE(FIRSTDATE('Calendário'[Date]);
                            ALL('Calendário'[Date]);
                            FILTER(
                                ALL(SalesTable);
                                SalesTable[ClienteId] = MAX(SalesTable[ClienteId])
                            ))

Thanks a lot for your help!

View solution in original post

4 REPLIES 4
MFelix
Super User
Super User

Hi @Asantos2020 ,

 

Measure are based on context and using the ALL function on your measure returns all the rows in a table, or all the values in a column, ignoring any filters that might have been applied. This function is useful for clearing filters and creating calculations on all the rows in a table.

 

Looking at your calculation and I'm assuming that your calendário table is connected to the sales what is happening is that you are picking up the minimum date of your calendar since you are ignoring all the filters (changing the context).

 

Try the following code instead:

FirstPurchase =
CALCULATE (
    FIRSTDATE ( SalesFactTable[Date] );
    ALL ( 'Calendário'[Date] );
    FILTER (
        ALL ( SalesFactTable[Customer]; SalesFactTable[Purchase Cycle] );
        SalesFactTable[Customer] = MAX ( SalesFactTable[Customer] )
            && SalesFactTable[Purchase Cycle] = MAX ( SalesFactTable[Purchase Cycle] )
    )
)

If this doesn't work can you share a sample of your data and expected result?

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hello @MFelix ,

 

Here is how I've fixed it:

Primeira Compra = CALCULATE(FIRSTDATE('Calendário'[Date]);
                            ALL('Calendário'[Date]);
                            FILTER(
                                ALL(SalesTable);
                                SalesTable[ClienteId] = MAX(SalesTable[ClienteId])
                            ))

Thanks a lot for your help!

Hi @Asantos2020 ,

 

On your example wasn't clear that one of the columns was a measure, but a measure is based on context and this can be given by other measures on your case that is what happened.

 

 

Regards,

Mfelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hello, @MFelix .

 

Sorry I forgot to mention that the Purchase Cycle is a measure that has FirstPurchase as a calculation factor. Therefore, I'd assume that I should use another implicit column in the DAX formula, like CustomerID...?

I did so, but the column presented the correct first purchase for a couple of customers in the list only. The majority resulted in 31/12/1899.

At the end, we need to have both FIRST PURCHASE and LASTPURCHASE ignore date filter, so that I can have a Purchase Cycle for customer x, y and z to let Sales Team know as to those customers' purchasing profile.

Appreciate your attention on this one!

 

Regards,

Antonio Santos

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.