Forum Discussion

Schmidtmayer's avatar
Schmidtmayer
Icon for Helper II rankHelper II
6 years ago
Solved

Calculating Coefficient of Variation

Hello everyone 😃 I do have a table containing the following columns: Personal Number, Date, Team, Project, TimeCategory, Time There are multiple Personal Numbers per Team, multiple Teams pe...
  • Anonymous's avatar
    Anonymous
    6 years ago

    All filtering is one-way only from a dimension to the fact table.

     

    // Dimensions:
    // 		Employee connected to FactTable[PIN] (1:*)
    // 		Calendar connected to FactTable[Date] (1:*)
    // 		Team connected to FactTable[TeamId] (1:*)
    // 		Project connected to FactTable[ProjectId] (1:*)
    // 		TimeCategory connected to FactTable[TimeCategoryId] (1:*)
    // All *Id fields are hidden in dimensions.
    //
    // All columns in the FactTable must be hidden.
    // Only measures can be visible. All slicing is
    // done through dimensions. This is the correct
    // star schema model.
    
    // Define the following measures. They work for any
    // slice for any dimension. In particular for 
    // slices on Employee.
    
    [Total] = SUM( FactTable[Hours] )
    
    [Illness] =
    	CALCULATE(
    		[Total],
    		KEEPFILTERS( TimeCategory[TimeCategoryId] = "Illness" )
    	)
    
    [IllnessQuota] = DIVIDE( [Illness], [Total] )
    	
    [Proportion To Team] =
    var __totalForEmps = [Total]
    var __teamsOfEmps =
    	summarize(
    		FactTable,
    		Team[TeamId]
    	)
    var __totalForTeams =
    	calculate(
    		[Total],
    		__teamsOfEmps,
    		all( Employee ),
    		all( Team )
    	)
    var __result =
    	divide( __totalForEmps, __totalForTeams )
    return
    	__result
    	
    	
    [VC for Team] =
    var __oneTeamVisible = hasonevalue( Team[TeamId] )
    var __team = 
    	SUMMARIZE(
    		FactTable,
    		Team[TeamId]
    	)
    var __employees =
    	SUMMARIZE(
    		FactTable,
    		Employee[PIN]
    	)
    var __numerator =
    	SQRT(
    		SUMX(
    		
    			__employees,
    			
    			var __iqForEmp = [IllnessQuota]
    			var __iqForTeam =
    				calculate(
    					[IllnessQuota],
    					__team,
    					all( Team ),
    					all( Employee )
    				)
    			var __propToTeam = [Proportion To Team]
    			var __result =
    				__propToTeam
    					* POWER( __iqForEmp - __iqForTeam, 2 )
    			return
    				__result
    			
    		)
    	)
    var __denominator = 
    	calculate(
    		[IllnessQuota],
    		__team,
    		all( Team ),
    		all( Employee )
    	)
    var __varCoeff =
    	DIVIDE( __numerator, __denominator )
    return
    	if( __oneTeamVisible, __varCoeff )

     

     

     

    Once you've implemented the correct model, please let me know how it goes. Thanks 🙂

     

    Best

    D