Forum Discussion
MONTH function error
- 6 years ago
hi Anonymous
First, you should know the difference between calculated column and calculated measure.
https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/
- Use a calculated column when you want to evaluate each row
- Use a measure when you need an aggregate
Your formula is used for a calculated column.
If you want to use the same logic to create a measure, please adjust the formula as below:
MTD LABEL JAN =
IF (
MONTH ( MAX ( MAXDATE1[MaxDate] ) ) = 01
&& CEILING ( DAY ( MAXDATE / 7 ), 1 )
< CALCULATE (
MAX ( Query1[MaxNumOfPayWeeksInMonth] ),
FILTER ( Query1, Query1[MONTH] = "01/2019" )
),
CALCULATE (
SUM ( Query1[MID_MONTH_NET_AMOUNT] ),
FILTER ( Query1, Query1[MONTH] = "01/2019" && Query1[WeekNum] = "<=2" )
),
CALCULATE (
SUM ( Query1[MTD_NET_AMOUNT] ),
FILTER ( Query1, Query1[MONTH] = "01/2019" )
)
)Regards,
Lin
hi Anonymous
First, you should know the difference between calculated column and calculated measure.
https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/
- Use a calculated column when you want to evaluate each row
- Use a measure when you need an aggregate
Your formula is used for a calculated column.
If you want to use the same logic to create a measure, please adjust the formula as below:
MTD LABEL JAN =
IF (
MONTH ( MAX ( MAXDATE1[MaxDate] ) ) = 01
&& CEILING ( DAY ( MAXDATE / 7 ), 1 )
< CALCULATE (
MAX ( Query1[MaxNumOfPayWeeksInMonth] ),
FILTER ( Query1, Query1[MONTH] = "01/2019" )
),
CALCULATE (
SUM ( Query1[MID_MONTH_NET_AMOUNT] ),
FILTER ( Query1, Query1[MONTH] = "01/2019" && Query1[WeekNum] = "<=2" )
),
CALCULATE (
SUM ( Query1[MTD_NET_AMOUNT] ),
FILTER ( Query1, Query1[MONTH] = "01/2019" )
)
)
Regards,
Lin