Forum Discussion
FZOU
Helper IV
6 years agoDax Soustract DATE
Hello, I need your help guys to achieve a formula. I have a column that containt "Year-Month" for exp : YearMonth 2019-01 2019-02 2019-03 N.. I have another column that contains number ...
- 6 years ago
Hi FZOU ,
Can you change the data type of column "YearMonth" from Text to Date? If yes, maybe you could try this:
Column = DATE ( YEAR ( 'Table'[YearMonth] ), MONTH ( 'Table'[YearMonth] ) - 'Table'[MonthN], DAY ( 'Table'[YearMonth] ) )And then format the new column as "yyyy-mm".
Greg_Deckler
Community Champion
6 years agoPerhaps:
Column =
VAR __YearMonth = VALUE(SUBSTITUTE([YearMonth],"-",""))
VAR __NewYearMonth = (__YearMonth - [MonthN]) & ""
RETURN
LEFT(__NewYearMonth,4) & "-" & RIGHT(__NewYearMonth,2)- FZOU6 years ago
Helper IV
- Greg_Deckler6 years ago
Community Champion
Right, forgot the padded zero, try this one:
Column = VAR __YearMonth = VALUE(SUBSTITUTE([YearMonth],"-","")) VAR __NewYearMonth = (__YearMonth - [MonthN]) & "" RETURN LEFT(__NewYearMonth,4) & "-" & FORMAT(RIGHT(__NewYearMonth,2),"0#")Might be ## or 0#, one of them or both give a padded right-zero.
- FZOU6 years ago
Helper IV
Greg_Deckleri keep get the same wrong result