Forum Discussion
DAX for MIn/Max based on count
- 8 years ago
Hi Anonymous
Check this file here
Try this
Time_MaxCrime = VAR MaxCount = MAXX ( VALUES ( Table1[Time] ), CALCULATE ( COUNT ( Table1[Crime Type] ) ) ) RETURN CALCULATE ( CONCATENATEX ( FILTER ( VALUES ( Table1[Time] ), CALCULATE ( COUNT ( Table1[Crime Type] ) = MaxCount ) ), Table1[Time] ) )
Hi Anonymous
Check this file here
Try this
Time_MaxCrime =
VAR MaxCount =
MAXX ( VALUES ( Table1[Time] ), CALCULATE ( COUNT ( Table1[Crime Type] ) ) )
RETURN
CALCULATE (
CONCATENATEX (
FILTER (
VALUES ( Table1[Time] ),
CALCULATE ( COUNT ( Table1[Crime Type] ) = MaxCount )
),
Table1[Time]
)
)My godness, this is so perfect! Thank you so much Zubair_Muhammad
To get Time_MinCrime, I just replaced the MAXX with MINX in below formula but its not showing any value. Could you please provide me the folrmula to get the Min value as well?
Time_MaxCrime =
VAR MaxCount =
MAXX ( VALUES ( Table1[Time] ), CALCULATE ( COUNT ( Table1[Crime Type] ) ) )
RETURN
CALCULATE (
CONCATENATEX (
FILTER (
VALUES ( Table1[Time] ),
CALCULATE ( COUNT ( Table1[Crime Type] ) = MaxCount )
),
Table1[Time]
)
)
Thank you again!
- Zubair_Muhammad8 years agoCommunity Champion
Hi Anonymous
For Time with Min Count, try this
Time_MinCrime = VAR MinCount = MINX ( VALUES ( Table1[Time] ), CALCULATE ( COUNT ( Table1[Crime Type] ) ) ) RETURN CALCULATE ( CONCATENATEX ( FILTER ( VALUES ( Table1[Time] ), CALCULATE ( COUNT ( Table1[Crime Type] ) = MinCount ) ), Table1[Time] ) )- Anonymous8 years agoNot applicable
Thanks for this but this Min formula is not working as expected. Initially its not showing any data but when I select any crime type its showing weired values like 1816, 1216 etc. The max formula is working perfectly like when no crime is selected then shwoing max time for all crimes and even one crime selected then showing its corresponding time. I used the following with the table names-
Time_MinCrime =
VAR MinCount =
MINX ( VALUES ( CrimeDataAnalysisParsed[MeanHour] ), CALCULATE ( COUNT ( CrimeDataAnalysisParsed[ID] ) ) )
RETURN
CALCULATE (
CONCATENATEX (
FILTER (
VALUES ( CrimeDataAnalysisParsed[MeanHour] ),
CALCULATE ( COUNT ( CrimeDataAnalysisParsed[ID] ) = MinCount )
),
CrimeDataAnalysisParsed[MeanHour]
)
)Please advise.
Thanks!
- Zubair_Muhammad8 years agoCommunity Champion
Hi Anonymous,
This might be happening because they are more than one time with same number of counts i.e. minimum count
Time 18 and Time 16