Forum Discussion
How to do grouping in specific date
- 9 years ago
Hi firdaus_akmal28,
In this scenario, you can consider two solutions to display festival type in a new column.
Solution 1.
You can add a calculated column directly using this formula:Festival = IF ( FestivalTable[Date] >= DATE ( 2016, 1, 1 ) && FestivalTable[Date] <= DATE ( 2016, 1, 5 ), "Festival A", IF ( FestivalTable[Date] >= DATE ( 2016, 2, 25 ) && FestivalTable[Date] <= DATE ( 2016, 2, 28 ), "Festival B", IF ( FestivalTable[Date] >= DATE ( 2016, 3, 6 ) && FestivalTable[Date] <= DATE ( 2016, 3, 7 ), "Festival C", IF ( FestivalTable[Date] >= DATE ( 2016, 4, 16 ) && FestivalTable[Date] <= DATE ( 2016, 5, 2 ), "Festival D", BLANK () ) ) ) )But if you have many festival types, the above expression will be complex. Then, you can try below solution.
Solution 2.
Suppose there are several columns in your source table, now you need to create a new table which only includes one date column.
FestivalTable2 = SELECTCOLUMNS(FestivalTable,"Date",FestivalTable[Date])
Create an extra table (in my test, it's Table1) to list the mapping relationship between date range and festival type.
Cross join above two tables. And add a calculated column (in my test, it's Flag).
Table2 = CROSSJOIN(Table1,FestivalTable2) Flag = IF ( Table2[Date] >= Table2[StartDate] && Table2[Date] <= Table2[EndDate], Table2[Festival], BLANK () )Create another calculate table to filter records from Table2.
Table3 = CALCULATETABLE(Table2,Table2[Flag]<>BLANK())
At last, in your original, use LOOKUPVALUE function to add a new column.
Festival = LOOKUPVALUE(Table3[Flag],Table3[Date],FestivalTable[Date])
Best regards,
Yuliana Gu
In this scenario, you can consider two solutions to display festival type in a new column.
Solution 1
You can add a calculated column directly using this formula:
Festival =
IF (
FestivalTable[Date] >= DATE ( 2016, 1, 1 )
&& FestivalTable[Date] <= DATE ( 2016, 1, 5 ),
"Festival A",
IF (
FestivalTable[Date] >= DATE ( 2016, 2, 25 )
&& FestivalTable[Date] <= DATE ( 2016, 2, 28 ),
"Festival B",
IF (
FestivalTable[Date] >= DATE ( 2016, 3, 6 )
&& FestivalTable[Date] <= DATE ( 2016, 3, 7 ),
"Festival C",
IF (
FestivalTable[Date] >= DATE ( 2016, 4, 16 )
&& FestivalTable[Date] <= DATE ( 2016, 5, 2 ),
"Festival D",
BLANK ()
)
)
)
)
But if you have many festival types, the above expression will be complex. Then, you can try below solution.
Solution 2
Suppose there are several columns in your source table, now you need to create a new table which only includes one date column.
FestivalTable2 = SELECTCOLUMNS(FestivalTable,"Date",FestivalTable[Date])
Create an extra table to list the mapping relationship between date range and festival type.
Cross join above two tables. And add a calculated column.
Table2 = CROSSJOIN(Table1,FestivalTable2)
Flag =
IF (
Table2[Date] >= Table2[StartDate]
&& Table2[Date] <= Table2[EndDate],
Table2[Festival],
BLANK ()
)
Create another calculate table to filter records from Table2.
Table3 = CALCULATETABLE(Table2,Table2[Flag]<>BLANK())
At last, in your original, use LOOKUPVALUE function to add a new column.
Festival = LOOKUPVALUE(Table3[Flag],Table3[Date],FestivalTable[Date])
Best regards,
Yuliana Gu