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
Anonymous
Not applicable

Row Context not removing filter in IF Statement

Hi,

 

I'm hoping someone can help.

 

I'm trying to undestand why my SUMX formula appears to not be taking into account the ALL to remove the filter on the months (I need it take the volume across the full 12 months rather than the invdividual month's volume).  In theory all values should come out as 0 but instead it appears to be passing the IF statement.

 

If I remove the SUMX the formula appears to be working fine.

 

DAX Formula:

SUMX('PBCS Pull',
        IF(
             Calculate(
                    SUM('PBCS Pull'[.Prev Volume]),
                    ALL('PBCS Pull'[Month])
             ) = 0,
            ([Curr Rev/Vol]-[Prev Rev/Volume])* 'PBCS Pull'[.Curr Volume],
            0
        )
)
 
 

 

Below is the data Set in Excel

ProductMonth.Prev Volume.Prev Rev.Curr Volume.Curr Rev.Prev Rev/Volume.Curr Rev/Volume
Product 1Jan0.000.002.1617.32                                -                            8.02
Product 1Feb0.000.002.6915.46                                -                            5.74
Product 1Mar0.000.004.4527.12                                -                            6.09
Product 1Apr0.000.000.281.78                                -                            6.27
Product 1May0.000.000.281.71                                -                            6.11
Product 1Jun0.000.000.452.77                                -                            6.17
Product 1Jul0.000.000.744.39                                -                            5.95
Product 1Aug0.000.000.030.15                                -                            5.94
Product 1Sep0.000.000.030.16                                -                            5.94
Product 1Oct5.4038.890.452.39                           7.20                          5.36
Product 1Nov5.1353.540.371.96                         10.44                          5.31
Product 1Dec1.6210.070.281.50                           6.21                          5.41

 

Thanks in advance

2 ACCEPTED SOLUTIONS

Hi @Anonymous ,

 

According to your expected output, would you please use the following calculated column:

 

 

Column =

SUMX (

    'PBCS Pull',

    IF (

        CALCULATE ( SUM ( 'PBCS Pull'[Prev Volume] ), ALLEXCECT ( 'PBCS Pull', 'PBCS Pull'[Prouduct] ) ) = 0,

       'PBCS Pull'[Curr Rev],

        0

    )

)

 

 

Best Regards,

Dedmon Dai

View solution in original post

Hi @Anonymous ,

I would suggest to have a look a this article to start: https://www.microsoftpressstore.com/articles/article.aspx?p=2449191.

DAX experts are way better than me to explain things. Anyway, to the best of my knoledge:

Question: Just to ensure I'm reading this correctly does this mean that measures technically create evaluation context to iterate through based on ALL rows in the given table?

Answer: I would't say that "measures technically create evaluation context". The evaluation context is created by: filter context (row/column selection, slicers, filter selection) and row context (calculated columns, row iteration functions).

Question: Thus as an example even though I've removed all filters on months its still filtering for "2.2" only in .Curr Volume Column (given Jan only has 2.2 even though the month filter is removed Jan is still the only month applicable in the output from calculate)? 

Answer: I would say that in your example all the columns are filtering unless you explicitely remove/modify the filter (eg: ALL, ALLEXCEPT)

Question: I assume the above still holds even if my visualization only includes the "Product" & "Month" column given the SUMX is referencing off of the full PBCS Pull Table?

Answer: That's correct

 

Hope it helps.

Cheers,

Marco

View solution in original post

9 REPLIES 9
Greg_Deckler
Super User
Super User

Probably because you do not have an ALL in your outer SUMX. That is super bizarre formula structure by the way, extremely weird.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Sorry I'm not sure I follow.

I'm fairly new to power BI so bare with my on the questions and the poor formula structure.

Any feedback on best practices are welcomed.
Thanks

Hi @Anonymous ,

 

Please try the following dax:

 

 

Column =

SUMX ('PBCS Pull',

IF (

CALCULATE ( SUM ( 'PBCS Pull'[Prev Volume] ), ALL ( 'PBCS Pull' ) ) = 0,

( 'PBCS Pull'[Curr Rev/Volume] - 'PBCS Pull'[Prev Rev/Volume] )

* 'PBCS Pull'[Prev Volume],

0

)

)

 

Untitled picture2.png

 

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

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

Hi Dedmon,

 

The issue is that change in the ALL criteria should be month specific.  In theory it should be passing the if statement if the "Prev Volume" SUM from Jan to Dec = 0 for the specific product.

If another product is added without Prev Volume it should pass the IF statement as true.  Where as the suggested formula makes everything 0.

Please see below with the ideal output.

ProductMonth.Prev Volume.Prev Rev.Curr Volume.Curr Rev.Prev Rev/Volume.Curr Rev/Volume Expected Output
          
Product 1Jan                        -                   -                       2.2                    17.3                                  -                                 8.0 0.0
Product 1Feb                        -                   -                       2.7                    15.5                                  -                                 5.7 0.0
Product 1Mar                        -                   -                       4.5                    27.1                                  -                                 6.1 0.0
Product 1Apr                        -                   -                       0.3                      1.8                                  -                                 6.3 0.0
Product 1May                        -                   -                       0.3                      1.7                                  -                                 6.1 0.0
Product 1Jun                        -                   -                       0.4                      2.8                                  -                                 6.2 0.0
Product 1Jul                        -                   -                       0.7                      4.4                                  -                                 6.0 0.0
Product 1Aug                        -                   -                       0.0                      0.2                                  -                                 5.9 0.0
Product 1Sep                        -                   -                       0.0                      0.2                                  -                                 5.9 0.0
Product 1Oct                      5.4             38.9                     0.4                      2.4                                7.2                               5.4 0.0
Product 1Nov                      5.1             53.5                     0.4                      2.0                             10.4                               5.3 0.0
Product 1Dec                      1.6             10.1                     0.3                      1.5                                6.2                               5.4 0.0
Product 2Jan                        -                   -                    34.3                  248.8                                  -                                 7.3 248.8
Product 2Feb                        -                   -                    65.2                  502.9                                  -                                 7.7 502.9
Product 2Mar                        -                   -                    77.6                  558.6                                  -                                 7.2 558.6
Product 2Apr                        -                   -                    50.6                  377.6                                  -                                 7.5 377.6
Product 2May                        -                   -                    71.8                  539.9                                  -                                 7.5 539.9
Product 2Jun                        -                   -                    59.2                  446.8                                  -                                 7.5 446.8
Product 2Jul                        -                   -                    50.9                  334.2                                  -                                 6.6 334.2
Product 2Aug                        -                   -                    45.1                  309.6                                  -                                 6.9 309.6
Product 2Sep                        -                   -                    43.1                  304.3                                  -                                 7.1 304.3
Product 2Oct                        -                   -                    38.1                  268.4                                  -                                 7.0 268.4
Product 2Nov                        -                   -                    36.8                  270.0                                  -                                 7.3 270.0
Product 2Dec                        -                   -                    45.6                  324.4                                  -                                 7.1 324.4

Let me know your thoughts.

 

Thanks,

Alex 

Hi @Anonymous ,

 

According to your expected output, would you please use the following calculated column:

 

 

Column =

SUMX (

    'PBCS Pull',

    IF (

        CALCULATE ( SUM ( 'PBCS Pull'[Prev Volume] ), ALLEXCECT ( 'PBCS Pull', 'PBCS Pull'[Prouduct] ) ) = 0,

       'PBCS Pull'[Curr Rev],

        0

    )

)

 

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

Thanks Dedmon this worked.  Is there a reason why ALL('PBCS Pull'[Month]) doesn't work?

Thanks,

Alex 

The reason why ALL('PBCS Pull'[Month]) doesn't work is because of the evaluation context of your IF function. Both if you use your formula in a calculated column and in a measure, the evaluation context comes from the original row context:

  • Calculated column: row context based on the current row. It includes all the columns
  • Measure: row context created by SUMX that iterates the rows. It includes all the columns

In both cases the row context is transformed in a filter context by the use of CALCULATE according to the context transition rule.

At this point, IF...SUM is in an evaluation context filtered by all the columns. If you use ALL('PBCS Pull'[Month]) you remove the filter only by Month column. What you need is to remove all filters but Product and that's why you have to use ALLEXCEPT(Product).

Hope it helps 🙂

Anonymous
Not applicable

Hi Marco,

 

Thank you for the explaination.  Just to ensure I'm reading this correctly does this mean that measures technically create evaluation context to iterate through based on ALL rows in the given table?  Ie. when it iterates through the first row it is technically filtering the following:
Product: Product 1

Month: Jan

.Prev Volume: 0

.Prev Rev: 0

.Curr Volume: 2.2

.Curr Rev: 17.3

etc...

Thus as an example even though I've removed all filters on months its still filtering for "2.2" only in .Curr Volume Column (given Jan only has 2.2 even though the month filter is removed Jan is still the only month applicable in the output from calculate)?  I assume the above still holds even if my visualization only includes the "Product" & "Month" column given the SUMX is referencing off of the full PBCS Pull Table?

 

I'm still new to Power BI so really appreciate the help everyone has given.

 

Thanks,

Alex 

Hi @Anonymous ,

I would suggest to have a look a this article to start: https://www.microsoftpressstore.com/articles/article.aspx?p=2449191.

DAX experts are way better than me to explain things. Anyway, to the best of my knoledge:

Question: Just to ensure I'm reading this correctly does this mean that measures technically create evaluation context to iterate through based on ALL rows in the given table?

Answer: I would't say that "measures technically create evaluation context". The evaluation context is created by: filter context (row/column selection, slicers, filter selection) and row context (calculated columns, row iteration functions).

Question: Thus as an example even though I've removed all filters on months its still filtering for "2.2" only in .Curr Volume Column (given Jan only has 2.2 even though the month filter is removed Jan is still the only month applicable in the output from calculate)? 

Answer: I would say that in your example all the columns are filtering unless you explicitely remove/modify the filter (eg: ALL, ALLEXCEPT)

Question: I assume the above still holds even if my visualization only includes the "Product" & "Month" column given the SUMX is referencing off of the full PBCS Pull Table?

Answer: That's correct

 

Hope it helps.

Cheers,

Marco

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.