Forum Discussion

polman4's avatar
polman4
Helper I
3 years ago
Solved

Dax function ignores slicer

Hello,

 

I have the following measure that works fine. 

asdasd

 

% Pageviews = 
VAR _max =
    CALCULATE (
        MAX ( 'nw_content'[Week_Start_Date] ),
        FILTER (
            ALL ( 'nw_content' ), [Author_Clm] = MAX ( [Author_Clm] ) && [Week_Start_Date] < MAX ( [Week_Start_Date] )
        )
    )
VAR _pir =
    CALCULATE (
        SUM ( [Pageviews] ),
        FILTER ( 
            ALL( 'nw_content' ), [Author_Clm] = MAX ( [Author_Clm] ) && [Week_Start_Date] = _max )
        )
VAR _result =
    DIVIDE ( SUM ( [Pageviews] ), _pir ) - 1
RETURN
    IF ( _result = -1, "no data", _result )

 

My problem is that when i try to use any filter the results are wrong. From what i understand is the function all i use here: 

 
ALL( 'nw_content' ), [Author_Clm] = MAX ( [Author_Clm] ) && [Week_Start_Date] = _max ) on variable _pir is ignoring the filter.
 
Any way to replace the funtion "all" without breaking the whole code?
 
Thank you!
Grigoris
  • Hello polman4,
    Try the below Measure:
     
    diff =
    var _max = CALCULATE(
        MAX('Table'[Column])
        , FILTER(
            ALLEXCEPT('Table', 'Table'[Type])
            , [author] = MAX([author])
            && [Column] < MAX([Column])
        )
    )
    var _pir= CALCULATE(
        SUM([value])
        , FILTER(
            ALLEXCEPT('Table', 'Table'[Type])
            , [author] = MAX([author])
            && [Column] = _max
        )
    )
    var _result= DIVIDE(SUM([value]), _pir) - 1
    return IF(_result = -1, BLANK(), _result)

9 Replies

  • Hello ReneMoawad 

    Thank you for the reply. Didn't really understand what change to do. What part of code to replace?

     

    Thank you

    • ReneMoawad's avatar
      ReneMoawad
      Resolver III

      Instead of using ALL('nw_content') you can use ALL('nw_content'[Author_Clm], 'nw_content'[Week_Start_Date])

       

      % Pageviews =

      VAR _max =

          CALCULATE (

              MAX ( 'nw_content'[Week_Start_Date] ),

              FILTER (

                  ALL('nw_content'[Author_Clm], 'nw_content'[Week_Start_Date]), [Author_Clm] = MAX ( [Author_Clm] ) && [Week_Start_Date] < MAX ( [Week_Start_Date] )

              )

          )

      VAR _pir =

          CALCULATE (

              SUM ( [Pageviews] ),

              FILTER (

                  ALL('nw_content'[Author_Clm], 'nw_content'[Week_Start_Date]), [Author_Clm] = MAX ( [Author_Clm] ) && [Week_Start_Date] = _max )

              )

      VAR _result =

          DIVIDE ( SUM ( [Pageviews] ), _pir ) - 1

      RETURN

          IF ( _result = -1, "no data", _result )

      • polman4's avatar
        polman4
        Helper I

        This gives me back no data for the variable _pir 😕