Forum Discussion
Schmidtmayer
Helper II
6 years agoCalculating 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...
- Anonymous6 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
Greg_Deckler
Community Champion
6 years agoI'll have to look, I believe I cover Covariance in my upcoming book, DAX Cookbook. Comes out next week. But would need sample data. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
- Greg_Deckler6 years ago
Community Champion
Ah yes, here is the formula that I was using for covariance.
Covariance = VAR __Table = 'R04_Table' VAR __Count = COUNTROWS(__Table) VAR __AvgA = AVERAGEX(__Table,[A]) VAR __AvgB = AVERAGEX(__Table,[B]) VAR __Table1 = ADDCOLUMNS( __Table, "__Covariance", DIVIDE( ([A] - __AvgA) * ([B] - __AvgB), __Count ) ) RETURN SUMX(__Table1,[__Covariance])