If I have a column with Year and column with Month. How to determine the starting day of…
- User
If I have a column with Year and column with Month. How to determine the starting day of Month and Year using DAX?
- Assistant
To determine the starting day of a month and year in DAX, you can use the
STARTOFMONTHfunction, which returns the first date of the month for a given date. Here's how you can create a calculated column to get the starting day of the month and year:-
First, create a date column by combining the Year and Month columns. You can use the
DATEfunction to create a date from the year and month values. Here's an example:daxDateColumn = DATE(TableName[Year], TableName[Month], 1)Replace
TableNamewith the name of your table. This calculated column will create a date for the first day of each month in the respective year. -
Next, create a calculated column to get the starting day of the month and year using the
STARTOFMONTHfunction:
-
- User
How to determine the ending day of Month and Year using DAX?
- Assistant
To determine the ending day of a month and year in DAX, you can use the
ENDOFMONTHfunction, which returns the last date of the month for a given date. Here's how you can create a calculated column to get the ending day of the month and year:-
First, ensure you have a date column by combining the Year and Month columns. You can use the
DATEfunction to create a date from the year and month values. Here's an example:daxDateColumn = DATE(TableName[Year], TableName[Month], 1)Replace
TableNamewith the name of your table. This calculated column will create a date for the first day of each month in the respective year. -
Next, create a calculated column to get the ending day of the month and year using the
ENDOFMONTHfunction:daxEndOfMonth = ENDOFMONTH(TableName[DateColumn])
-
- User
Ending Day = DATEADD(DATEADD(DATE('Share_SKU_Month'[Year], 'Share_SKU_Month'[Month], 1), 1, MONTH), -1, DAY) Fix the error A table expression containing more than one column was specified in the call to function 'DATEADD'. This is not supported.
- Assistant
The error you're encountering is because the
DATEfunction expects three separate arguments for year, month, and day, but you're passing a table expression with multiple columns. To fix this, you can use theDATEfunction with theYEAR,MONTH, andDAYfunctions to extract the individual components from the table columns. Here's the corrected DAX expression:daxEnding Day = VAR CurrentDate = DATE('Share_SKU_Month'[Year], 'Share_SKU_Month'[Month], 1) VAR NextMonthDate = DATEADD(CurrentDate, 1, MONTH) VAR LastDayOfMonth = DATEADD(NextMonthDate, -1, DAY) RETURN LastDayOfMonthIn this corrected expression, we first create a variable
CurrentDatethat represents the first day of the month using theDATEfunction with theYearandMonthcolumns. Then, we create another variableNextMonthDatethat represents the first day of the next month using theDATEADDfunction. Finally, we create theLastDayOfMonthvariable by subtracting one day from theNextMonthDateusing the function. The statement then returns the value as the result of the calculated column. - User
Why the DAX for calculated column return blank rows Ending Day of Month = DATEADD('Share_SKU_Month'[Starting Day of Month],1,MONTH)
- Assistant
The DAX expression you provided calculates the first day of the next month, not the last day of the current month. The
DATEADDfunction adds a specified time interval to a given date. In your case, it adds one month to theStarting Day of Month.To calculate the last day of the month, you can use the following DAX expression for a calculated column:
daxEnding Day of Month = VAR CurrentDate = 'Share_SKU_Month'[Starting Day of Month] VAR EndOfMonth = EOMONTH(CurrentDate, 0) RETURN EndOfMonthThis expression creates a variable
CurrentDatethat represents the first day of the month. Then, it calculates the last day of the month using theEOMONTHfunction, which returns the last day of the month for a given date. TheRETURNstatement then returns theEndOfMonthvalue as the result of the calculated column.If you still see blank rows after applying this expression, make sure that the
Starting Day of Monthcolumn does not contain any null or blank values. If it does, you can either fill in the missing values or use theIFfunction to handle these cases in the calculated column expression.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.