Forum Discussion
Creating a new column with values from two other columns based on Date
Hi guys,
this is my problem:
I have a Date table and two following tables:
Table 1
| Date | Value |
| 01.02.2020 | 2€ |
| 01.03.2020 | 2€ |
| 01.04.2020 | 2€ |
| 01.05.2020 | 2€ |
Table 2
| 01.04.2020 | 5€ |
01.05.2020 | 5€ |
| 01.06.2020 | 5€ |
| 01.07.2020 | 5€ |
I would like to create a new column that contains all values from Table 1 until 31.03.2020. From 01.04.2020 it should contain the values of Table 2.
Wanted result:
Date | Value |
01.02.2020 | 2€ |
01.03.2020 | 2€ |
01.04.2020 | 5€ |
01.05.2020 | 5€ |
01.06.2020 | 5€ |
01.07.2020 | 5€ |
I have tried this formula to get this column:
Thank you for your support 🙂
- Anonymous6 years ago
Hi iiomarioii ,
Create a new table using below dax expression:
Table 2 = var _tablea=CALCULATETABLE('Table','Table'[Date]<=DATE(2020,3,31)) var _tableb=CALCULATETABLE('Table (2)','Table (2)'[Date]>=DATE(2020,4,1)) Return UNION(_tablea,_tableb)And you will see:
For the related .pbix file,pls click here.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!
2 Replies
- MFelix
Super User
Hi iiomarioii ,
Try the following code:
Column = IF ( 'Date'[Date] <= DATE ( 2020; 3; 31 ); CALCULATE ( SUM ( Table1[Value] ); FILTER ( Table1; Table1[Date] = 'Date'[Date] ) ); CALCULATE ( SUM ( Table2[Value] ); FILTER ( Table2; Table2[Date] = 'Date'[Date] ) ) )I'm assuming you are adding this column to the date table.
- AnonymousNot applicable
Hi iiomarioii ,
Create a new table using below dax expression:
Table 2 = var _tablea=CALCULATETABLE('Table','Table'[Date]<=DATE(2020,3,31)) var _tableb=CALCULATETABLE('Table (2)','Table (2)'[Date]>=DATE(2020,4,1)) Return UNION(_tablea,_tableb)And you will see:
For the related .pbix file,pls click here.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!