Forum Discussion
Switch Formula Help (summarizecolumn?)
- 8 years ago
Hi qthuynh,
Create the following measures:
MTD_Calcution = SUMX ( Data; IF ( MAX ( CurrentMonth[Current Month] ) = "YES"; CALCULATE ( TOTALMTD ( SUM ( Data[Value] ); 'Calendar'[Date] ) ); IF ( MONTH ( TODAY () - DAY ( TODAY () ) ) >= MONTH ( MAX ( 'Calendar'[Date] ) ); CALCULATE ( TOTALMTD ( SUM ( Data[Value] ); 'Calendar'[Date] ) ) ) ) )Total MTD = IF ( HASONEFILTER ( 'Calendar'[Date] ); [MTD_Calcution]; SUMX ( Data; [MTD_Calcution] ) )Add the last measure to your table.
Regards,
MFelix
- 8 years ago
Excellent solution MFelix. I went down a slightly different path.
Step 1 - Added a new calculated column to my date table
IsCurrentMonth = IF(MONTH(Dates_Table[Date]) = MONTH(TODAY()) && YEAR(Dates_Table[Date]) = YEAR(TODAY()),1,0)
Step 2 - Created new measure to exclude current month
Month excl = CALCULATE( SUM ( Data[Value] ), Dates_Table[IsCurrentMonth]=0 )
Step 3 - Changed name of original measure to Month incl
Month incl = SUM( Data[Value] )
Step 4 - Created Switch Measure referencing Month excl & incl and added it to the table
Month = SWITCH ( TRUE(),
VALUES ( 'Month View'[Month View] ) = "Yes", [Month incl],
VALUES ( 'Month View'[Month View] ) = "No", [Month excl],
0 )
Hi qthuynh,
Create the following measures:
MTD_Calcution =
SUMX (
Data;
IF (
MAX ( CurrentMonth[Current Month] ) = "YES";
CALCULATE ( TOTALMTD ( SUM ( Data[Value] ); 'Calendar'[Date] ) );
IF (
MONTH ( TODAY () - DAY ( TODAY () ) )
>= MONTH ( MAX ( 'Calendar'[Date] ) );
CALCULATE ( TOTALMTD ( SUM ( Data[Value] ); 'Calendar'[Date] ) )
)
)
)
Total MTD =
IF (
HASONEFILTER ( 'Calendar'[Date] );
[MTD_Calcution];
SUMX ( Data; [MTD_Calcution] )
)
Add the last measure to your table.
Regards,
MFelix
Excellent solution MFelix. I went down a slightly different path.
Step 1 - Added a new calculated column to my date table
IsCurrentMonth = IF(MONTH(Dates_Table[Date]) = MONTH(TODAY()) && YEAR(Dates_Table[Date]) = YEAR(TODAY()),1,0)
Step 2 - Created new measure to exclude current month
Month excl = CALCULATE( SUM ( Data[Value] ), Dates_Table[IsCurrentMonth]=0 )
Step 3 - Changed name of original measure to Month incl
Month incl = SUM( Data[Value] )
Step 4 - Created Switch Measure referencing Month excl & incl and added it to the table
Month = SWITCH ( TRUE(),
VALUES ( 'Month View'[Month View] ) = "Yes", [Month incl],
VALUES ( 'Month View'[Month View] ) = "No", [Month excl],
0 )