Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Optimizing Dax formula

Workday Number =
VAR CurrentMonth =
SELECTEDVALUE ( 'Date'[Year Month] )
VAR MonthTable =
FILTER (
ALL ( 'Date' ),
'Date'[Working Days] = "Weekday"
&& 'Date'[Year Month] = CurrentMonth
)
RETURN
IF (
SELECTEDVALUE ( Date[Working Days] ) <> "Weekday",
BLANK (),
RANKX ( MonthTable, CALCULATE ( AVERAGE ( Date[DayOfMonth] ) ),, ASC )
)

 

Can anyone tell me why is this formula not working on current version of power bi?

  • Anonymous 

     

    I would venture it is because your RANKX function doesn't have the column reference to rank the values by. Include a column reference after the table reference:

    RANKX ( MonthTable, MonthTable[...], CALCULATE ( AVERAGE ( Date[DayOfMonth] ) ),, ASC )

     

    See if that works.

     

    EDIT: you might also need an ALL or ALLSELECTED before the table expression, depending on the context you wish to calculate de Rank by:

    RANKX ( ALLSELECTED(MonthTable), MonthTable[...], CALCULATE ( AVERAGE ( Date[DayOfMonth] ) ),, ASC )

11 Replies

  • v-eachen-msft's avatar
    v-eachen-msft
    Community Support

    Hi Anonymous ,

     

    Please make sure your table names are consistent, otherwise errors will occur. Change table name to either 'Date' or Date.

     

  • PaulDBrown's avatar
    PaulDBrown
    Community Champion

    Anonymous 

     

    I would venture it is because your RANKX function doesn't have the column reference to rank the values by. Include a column reference after the table reference:

    RANKX ( MonthTable, MonthTable[...], CALCULATE ( AVERAGE ( Date[DayOfMonth] ) ),, ASC )

     

    See if that works.

     

    EDIT: you might also need an ALL or ALLSELECTED before the table expression, depending on the context you wish to calculate de Rank by:

    RANKX ( ALLSELECTED(MonthTable), MonthTable[...], CALCULATE ( AVERAGE ( Date[DayOfMonth] ) ),, ASC )

    • Anonymous's avatar
      Anonymous
      Not applicable

      It says the syntax is incorrect but everything looks fine

       
       



      • vanessafvg's avatar
        vanessafvg
        Community Champion

        www.daxformatter.com isn't throwing any errors.

         

        are you creating a calculated measure or calculated column?  also have you run this successfully before?