Hello @Tones,
Thank You for posting your query onto the Forum.
To achieve the results into the specific format I created a table. Below is the screenshot provided for the reference -
Now, I created the 4 measures one each for Total Value, Total Costs, Margin and Margin %. Below are the measures provided for the reference -
Total Value =
VAR _Current_Item = SELECTEDVALUE( 'Grouping Table'[Grouping] )
VAR _Total_Value_YTD =
CALCULATE( SUM( Data[Value] ) ,
DATESYTD( Dates[Date] ) )
VAR _Total_Value_MTD =
CALCULATE( SUM( Data[Value] ) ,
DATESMTD( Dates[Date] ) )
VAR _Total_Value_Today =
CALCULATE( SUM( Data[Value] ) ,
FILTER( ALLSELECTED( Dates ) ,
Dates[Date] = MAX( Data[Date] ) ) )
RETURN
SWITCH( TRUE() ,
_Current_Item = "YTD" ,
IF( ISBLANK( _Total_Value_YTD ) , 0 , _Total_Value_YTD ) ,
_Current_Item = "MTD" ,
IF( ISBLANK( _Total_Value_MTD ) , 0 , _Total_Value_MTD ) ,
_Current_Item = "Today" ,
IF( ISBLANK( _Total_Value_Today ) , 0 , _Total_Value_Today ) ,
0 )
Total Cost =
VAR _Current_Item = SELECTEDVALUE( 'Grouping Table'[Grouping] )
VAR _Total_Cost_YTD =
CALCULATE( SUM( Data[Cost] ) ,
DATESYTD( Dates[Date] ) )
VAR _Total_Cost_MTD =
CALCULATE( SUM( Data[Cost] ) ,
DATESMTD( Dates[Date] ) )
VAR _Total_Cost_Today =
CALCULATE( SUM( Data[Cost] ) ,
FILTER( ALLSELECTED( Dates ) ,
Dates[Date] = MAX( Data[Date] ) ) )
RETURN
SWITCH( TRUE() ,
_Current_Item = "YTD" ,
IF( ISBLANK( _Total_Cost_YTD ) , 0 , _Total_Cost_YTD ) ,
_Current_Item = "MTD" ,
IF( ISBLANK( _Total_Cost_MTD ) , 0 , _Total_Cost_MTD ) ,
_Current_Item = "Today" ,
IF( ISBLANK( _Total_Cost_Today ) , 0 , _Total_Cost_Today ) ,
0 )
Margin = [Total Value] - [Total Cost]
Margin % = DIVIDE( [Margin] , [Total Value] , 0 )
Finally, this is how the final results will look like. Below is the screenshot provided for the reference -
I’m also attaching the working of the PBIX file for the reference.
Hoping you find this useful and meets your requirements that you’ve been looking for.
Note: You can modify the formulas/measures as per your requirements. I’ve created them as per the provided template.
Thanks and Warm Regards,
Harsh
Grouping Values - Harsh.pbix (71.8 KB)