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

Filter context weirdness

Hi there!

 

Perhaps a newbie question, but I can't wrap my head around how a measure reacts to filters... 


I have a measure that calculates sum of sales for the most recent day in the data :

 

Max Day Sales =
CALCULATE(
SUMInvoices_LQ[InvoiceLine.Amount] ),
Invoices_LQ[PostDate_DateFormat]=MAXX(
ALLInvoices_LQ[PostDate_DateFormat] ),
Invoices_LQ[PostDate_DateFormat] )
)

When I create a table with Invoices_LQ[PostDate_DateFormat] and this measure, I can see indeed the sales for the last date for every Invoices_LQ[PostDate_DateFormat] line :
 
paulpassot_0-1656028898798.png

 

So far, so good. 

However, if I create another visual showing Invoices_LQ[PostDate_DateFormat] and I select a value in there, sometimes it changes my Max Day Sales measure :

 

paulpassot_1-1656028994601.png

 

On top of that, it only seems to do so for certain Invoices_LQ[PostDate_DateFormat] only, and I haven't been able to identify some sort of pattern.

I'm guessing it has to do with some sort of context filtering I'm not understanding.


Still fairly new to PowerBI but this has given me a pretty bad headache!!

Anyone has a clue?

Thanks a lot!!

1 ACCEPTED SOLUTION

@paulpassot 
Aparently this is Auto-Exist problem.

First step try to manually calculate the last day sales. If it does not match the result of my first solution then you need to have a date table that filters your data set. This will totally eleiminate the problem.

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

Hi @paulpassot 

please try

Max Day Sales =
VAR MaxDate =
    CALCULATE ( MAX ( Invoices_LQ[PostDate_DateFormat] ), REMOVEFILTERS () )
RETURN
    CALCULATE (
        SUM ( Invoices_LQ[InvoiceLine.Amount] ),
        Invoices_LQ[PostDate_DateFormat] = MaxDate,
        REMOVEFILTERS ()
    )

Hi, thanks for the quick reply!

 

Interestingly, it gives the same result across dates (which is good), but it doesn't seem to give the right number:

paulpassot_0-1656040127476.png

I would expect 4,744$, not 5,358$.

 

I understand the logic of your code though, and I can't figure out how it comes up to 5,358$

 

@paulpassot 
I don't know how your data looks like but seems to me there are other filters. You may try **bleep** this way

Max Day Sales =
VAR MaxDate =
    CALCULATE (
        MAX ( Invoices_LQ[PostDate_DateFormat] ),
        ALL ( Invoices_LQ[PostDate_DateFormat] )
    )
RETURN
    CALCULATE (
        SUM ( Invoices_LQ[InvoiceLine.Amount] ),
        Invoices_LQ[PostDate_DateFormat] = MaxDate,
        ALL ( Invoices_LQ[PostDate_DateFormat] )
    )

So strange... it gives me the same result as my initial formula. Randomly giving a different number depending on what I select in another visual:

 

Here it is ok, filtered on 21st of june

paulpassot_0-1656040864100.png

Here it gives me a different value (wrong) when filtered on the 20th of june:

paulpassot_1-1656040899095.png

My datamodel is incredibly simple: single table with sales transactions in rows, a column for price and a column for date. I made a calculated column that "rounds" the post date (which is datetime) to a regular date :

PostDate_DateFormat = DATE(YEAR(Invoices_LQ[InvoiceHeader.Column1.invoicePostDate]),MONTH(Invoices_LQ[InvoiceHeader.Column1.invoicePostDate]),DAY(Invoices_LQ[InvoiceHeader.Column1.invoicePostDate]))
 
That's the column I leverage in my Max Day Sales formula. Do you think it could come from there?

 

@paulpassot 
Aparently this is Auto-Exist problem.

First step try to manually calculate the last day sales. If it does not match the result of my first solution then you need to have a date table that filters your data set. This will totally eleiminate the problem.

amitchandak
Super User
Super User

@paulpassot , Try like

Max Day Sales =
CALCULATE(
SUM( Invoices_LQ[InvoiceLine.Amount] ),
lastdate(Invoices_LQ[PostDate_DateFormat] )
)

 

for date

MAxx(ALLInvoices_LQ[PostDate_DateFormat] ), Invoices_LQ[PostDate_DateFormat] )

Unfortunately it doesn't work, it gives me the values for each date:

 

paulpassot_0-1656038513213.png

 

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