Forum Discussion
DATEADD using a month not a date
Hi!
I have a table that has only months and not a complete date. For example instead of having 20210708, I have 202107 (month).
This table is connected to the calendar using the month column.
I am trying to sum a column af this table for the last 12 and 24 months. So take the last 12 or 24 months and then sum the column to obtain the total value of the last 112 or 24 months.
I tried with this formula:
CALCULATE(DATEADD(LASTNONBLANK('Calendar'[Date] ,SUM(GiacenzaMagazzini[ValoreGiacenza])) ,-12 ,MONTH))
Is there a way to do it using the month coulmn I have in my calendar?
Thanks,
Hi carlottaf ,
Try the following steps:
Step 1,new column on GiacenzaMagazzini:
date = DATE(LEFT(GiacenzaMagazzini[month],4),RIGHT(GiacenzaMagazzini[month],2),1)Step 2,Use the following dax to create a new measure:
final = CALCULATE ( SUM ( 'GiacenzaMagazzini'[ValoreGiacenza]), DATESBETWEEN ( 'Calendar'[Date], CALCULATE(DATEADD(LASTNONBLANK('Calendar'[Date] ,SUM(GiacenzaMagazzini[ValoreGiacenza])) ,-12 ,MONTH)), LASTDATE ( 'Calendar'[Date] ) ) )Final get:
Wish it is helpful for you!
You could download my pbix flie if you need!
Best Regards
Lucien
3 Replies
- CNENFRNL
Community Champion
DATEADD(<dates>,<number_of_intervals>,<interval>)You use either the name of a column containing dates or a one column table containing dates.
- carlottafFrequent Visitor
So if I have no column containing dates I can't use this formula, correct?
Can I use something else?
- v-luwang-msft
Community Support
Hi carlottaf ,
Try the following steps:
Step 1,new column on GiacenzaMagazzini:
date = DATE(LEFT(GiacenzaMagazzini[month],4),RIGHT(GiacenzaMagazzini[month],2),1)Step 2,Use the following dax to create a new measure:
final = CALCULATE ( SUM ( 'GiacenzaMagazzini'[ValoreGiacenza]), DATESBETWEEN ( 'Calendar'[Date], CALCULATE(DATEADD(LASTNONBLANK('Calendar'[Date] ,SUM(GiacenzaMagazzini[ValoreGiacenza])) ,-12 ,MONTH)), LASTDATE ( 'Calendar'[Date] ) ) )Final get:
Wish it is helpful for you!
You could download my pbix flie if you need!
Best Regards
Lucien