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
GoncaloCare
Helper I
Helper I

Need some help with calculated measures with filters

Hi everyone. 

I need some help when calculating a measure.

So, I have this measure here:

 

Mat1valor = CALCULATE(SUM(Query3[EUR]), Query3[MAT]="Mat1")

 

And then, I want to calculate the variation of "Mat2". 

So, I do:

 

VariacaoMAT1 = ( ( [Mat1valor] / CALCULATE(SUM(Query3[EUR]), Query3[MAT]="Mat2" ) - 1 ))

 

 

And then, I select the filter in the filter menu (I do this to apply MAT1 to other graphs):

GoncaloCare_0-1619616051501.png

 

And, especially the second measure works well even though I'm selecting "Mat1" filter.

 

But, I have another 2 measures that I do:

 

NVisitasMat1 = SUMX (
    SUMMARIZE ( Filter(Query3, Query3[MAT]="Mat1") , Query3[id_fatura_unico], Query3[Contagem] , "Total Average", Query3[Contagem] ),
    [Total Average]
)

 

and then the variation:

 

VariacaoNvisitasMat1 = ( ( [NVisitasMat1] / SUMX (
    SUMMARIZE ( Filter(Query3, Query3[MAT]="Mat2") , Query3[id_fatura_unico], Query3[Contagem] , "Total Average", Query3[Contagem] ),
    [Total Average]
) ) - 1 )

 

 

The problem is that, in this case, the variation gives me "Infinity" because the sumx is 0 because I have the filter in "Mat1" and the filter on the measure is "Mat2". The strange thing is that on the variation above, everything works fine.

 

How can I make the "VariacaoNvisitasMat1" measure "forget" the selected filter?

 

Hope you can help me! Best regards!

 

 

 
1 ACCEPTED SOLUTION

Hi @GoncaloCare ,

 

VariacaoMAT1 =
(
    (
        [Mat1valor]
            / CALCULATE ( SUM ( Query3[EUR] ), Query3[MAT] = "Mat2" ) - 1
    )
)
VariacaoMAT1 - 2 =
(
    (
        [Mat1valor]
            / CALCULATE (
                SUM ( Query3[EUR] ),
                FILTER ( ALL ( Query3[MAT] ), Query3[MAT] = "Mat2" )
            ) - 1
    )
)

 

Since [VariacaoMAT1] works the same as [VariacaoMAT1 - 2], try to add "ALL(Query3[MAT])" at the end.

VariacaoNvisitasMat1 =
[NVisitasMat1]
    / CALCULATE (
        SUMX (
            SUMMARIZE (
                FILTER ( Query3, Query3[MAT] = "Mat2" ),
                Query3[id_fatura_unico],
                Query3[Contagem],
                "Total Average", Query3[Contagem]
            ),
            [Total Average]
        ),
        ALL ( Query3[MAT] )
    ) - 1

 

 

 

Best Regards,

Icey

 

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

4 REPLIES 4
GoncaloCare
Helper I
Helper I

Hi.

I forgot to put a link. Here is a link with fake data. 

What I want is, if I select "MAT1" on filters, I want the right value to work properly and not show "Blank".

https://www.dropbox.com/s/0tq98cozqtlpjql/testev2.pbix?dl=0

Hi @GoncaloCare ,

 

VariacaoMAT1 =
(
    (
        [Mat1valor]
            / CALCULATE ( SUM ( Query3[EUR] ), Query3[MAT] = "Mat2" ) - 1
    )
)
VariacaoMAT1 - 2 =
(
    (
        [Mat1valor]
            / CALCULATE (
                SUM ( Query3[EUR] ),
                FILTER ( ALL ( Query3[MAT] ), Query3[MAT] = "Mat2" )
            ) - 1
    )
)

 

Since [VariacaoMAT1] works the same as [VariacaoMAT1 - 2], try to add "ALL(Query3[MAT])" at the end.

VariacaoNvisitasMat1 =
[NVisitasMat1]
    / CALCULATE (
        SUMX (
            SUMMARIZE (
                FILTER ( Query3, Query3[MAT] = "Mat2" ),
                Query3[id_fatura_unico],
                Query3[Contagem],
                "Total Average", Query3[Contagem]
            ),
            [Total Average]
        ),
        ALL ( Query3[MAT] )
    ) - 1

 

 

 

Best Regards,

Icey

 

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

amitchandak
Super User
Super User

@GoncaloCare , Without filter function filter in calculate, is same as a filter with all

 

try like

VariacaoNvisitasMat1 = ( ( [NVisitasMat1] / SUMX (
    SUMMARIZE ( Filter(All(Query3), Query3[MAT]="Mat2") , Query3[id_fatura_unico], Query3[Contagem] , "Total Average", Query3[Contagem] ),
    [Total Average]
) ) - 1 )

 

Check this - http://dataap.org/blog/2019/04/22/difference-between-calculate-with-and-without-filter-expression/

Hi @amitchandak 

Thanks for the reply. 

I already tried this and it didn't work. And it was very strange.

To make a comparison, I remove the filters, and I have these two measures:

NVisitasMat2 = SUMX (
    SUMMARIZE ( Filter(Query3, Query3[MAT]="Mat2") , Query3[id_fatura_unico], Query3[Contagem] , "Total Average", Query3[Contagem] ),
    [Total Average]
)
NVisitasMat2v2 = SUMX (
    SUMMARIZE ( Filter(all(Query3), Query3[MAT]="Mat2") , Query3[id_fatura_unico], Query3[Contagem] , "Total Average", Query3[Contagem] ),
    [Total Average]
)

As you can see, the only difference is the "All(query3)". 

But the results are different (the correct is the left one):

GoncaloCare_0-1619618551467.png

What can be causing this?

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.