Forum Discussion
Anonymous
5 years agoNot applicable
HIstogram measure
Hi, I would like to create a graph like a kind of Histogram. The data is about logging into an application. I have a row per user connected to the application, and the same user can be connected s...
- 5 years ago
// You have to create a disconnected table // that will store the numbers (of days) you want. // That would be 1,2,3,...,N. N will probably be 31 // but my measure works for ANY PERIOD OF TIME, not // only a month. // // Let's call it 'Connected Days'. It'll have // just one column: 'Connected Days'[Number Of Days]. // Then assume you've also got the table as // shown in your post. You can then write a measure // that'll work against the 'Connected Days' table. [# Users Connected] = IF( HASONEFILTER( 'Connected Days'[Number Of Days] ), // For the visible Number of Days find the number // of users in your T table (honoring all the // other possible filters) that were connected // during the currently visible period for that // number of days. var __selectedNumOfDays = SELECTEDVALUE( 'Connected Days'[Number Of Days] ) var __usersWithNumberOfDays = ADDCOLUMNS( DISTINCT( T[User] ), "@NumOfDays", CALCULATE( DISTINCTCOUNT( T[Date] ) ) ) var __numberOfDaysWithNumOfUsers = GROUPBY( __usersWithNumberOfDays, [@NumOfDays], "@NumOfUsers", SUMX( CURRENTGROUP(), 1 ) ) var __output = MINX( filter( __numberOfDaysWithNumOfUsers, [@NumOfDays] = __selectedNumberOfDays ), [@NumOfUsers] ) return __output )
daxer-almighty
Solution Sage
5 years ago// You have to create a disconnected table
// that will store the numbers (of days) you want.
// That would be 1,2,3,...,N. N will probably be 31
// but my measure works for ANY PERIOD OF TIME, not
// only a month.
//
// Let's call it 'Connected Days'. It'll have
// just one column: 'Connected Days'[Number Of Days].
// Then assume you've also got the table as
// shown in your post. You can then write a measure
// that'll work against the 'Connected Days' table.
[# Users Connected] =
IF( HASONEFILTER( 'Connected Days'[Number Of Days] ),
// For the visible Number of Days find the number
// of users in your T table (honoring all the
// other possible filters) that were connected
// during the currently visible period for that
// number of days.
var __selectedNumOfDays =
SELECTEDVALUE( 'Connected Days'[Number Of Days] )
var __usersWithNumberOfDays =
ADDCOLUMNS(
DISTINCT( T[User] ),
"@NumOfDays",
CALCULATE(
DISTINCTCOUNT( T[Date] )
)
)
var __numberOfDaysWithNumOfUsers =
GROUPBY(
__usersWithNumberOfDays,
[@NumOfDays],
"@NumOfUsers",
SUMX( CURRENTGROUP(), 1 )
)
var __output =
MINX(
filter(
__numberOfDaysWithNumOfUsers,
[@NumOfDays] = __selectedNumberOfDays
),
[@NumOfUsers]
)
return
__output
)Anonymous
5 years agoNot applicable
Thanks a lot, its working great