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

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?

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
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 )





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

11 REPLIES 11
PaulDBrown
Community Champion
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 )





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

@PaulDBrown  It's working Thanks

v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

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

1-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
vanessafvg
Super User
Super User

what error message are you getting?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

It says the syntax is incorrect but everything looks fine

 
 



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

 

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





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

I'm creating a calculated column, yaa it was running before but now it's not

This is the error i getThis is the error i get

 

Hi,

 

No idea if it would solve it but you could try adding a ' before and after the table name and to remove the calculate something like below

RETURN
IF(SELECTEDVALUE ( 'Date'[Working Days] ) <> "Weekday",

BLANK (),
RANKX ( MonthTable, AVERAGE ( 'Date'[DayOfMonth]  ),, ASC )
)

 

 

Anonymous
Not applicable

I don't think it will work, error.PNG

@Anonymous  thats a different error now though which is strange.  i see you changed the field names or is that the real names ?

 

if you go back to the original (although i can't see how this will work but i guess you have to eliminate all possiblities), and just add apostrophes so its named consistenly without does that make a difference?

 

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 )
)





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




eish 🙂

 

i can't see the fulll error, and you say the only difference is you have updated your power bi to the latest thats the only change?  strange that it doesn't actually underline the issue.   





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




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.