Forum Discussion
MEASURE NETWORDAYS WORKS DIFFERENTLY
I use two measures that a priori should be the same, only that one uses on weekdays. When I use the function with DATEDIFF it works well and respects the dimcalendar filter, which is in star format. The problem comes when using NETWORKDAYS, it breaks the filter and returns a value of 2023. I know that the function to calculate one of the two dates has an ALL but it is a previous step to the calculation of the difference in dates... Because one inhibits him and the other does not?
- Anonymous2 years ago
Hi Anonymous ,
This is because you filter from the slicer.
First of all, I reproduced your scenario.
If you return MAXDAY, you will find out that threre's blank returned in date 1/1/2023.
So, when you select 2024 in the slicer, it will return the result as follows:
To fix this, you can add a if condtition.
Since my slicer is created by the year of the date hierarchy, I used SELECTEDVALUE('Table'[Date].[Year]) to locate the year from the slicer. If your slicer's year field is from a column, not a hierarchy, just use SELECTEDVALUE('TABLENAME'[YEAR]).
Here's the modified measure:
NETWORKDAYS = VAR MAXDAY=MAX('Table'[Date]) VAR FECHA=MAXX(ALL('Table'),[Date]) VAR difflaborables=NETWORKDAYS(MAXDAY,FECHA) RETURN IF(SELECTEDVALUE('Table'[Date].[Year])=YEAR(MAXDAY),difflaborables)Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- AnonymousNot applicable
Hi Anonymous ,
This is because you filter from the slicer.
First of all, I reproduced your scenario.
If you return MAXDAY, you will find out that threre's blank returned in date 1/1/2023.
So, when you select 2024 in the slicer, it will return the result as follows:
To fix this, you can add a if condtition.
Since my slicer is created by the year of the date hierarchy, I used SELECTEDVALUE('Table'[Date].[Year]) to locate the year from the slicer. If your slicer's year field is from a column, not a hierarchy, just use SELECTEDVALUE('TABLENAME'[YEAR]).
Here's the modified measure:
NETWORKDAYS = VAR MAXDAY=MAX('Table'[Date]) VAR FECHA=MAXX(ALL('Table'),[Date]) VAR difflaborables=NETWORKDAYS(MAXDAY,FECHA) RETURN IF(SELECTEDVALUE('Table'[Date].[Year])=YEAR(MAXDAY),difflaborables)Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- some_bih
Community Champion
without model and relationships it is hard to spot issues.
Still, using ALL like in your case ALL(facttable) use the ALL function to remove all context filters on the table. This could be one of possible reason why you got unexpected output. For details about ALL function check link