Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ShNBl84
Helper II
Helper II

Calculating the mode of the values of multiple measures

I am trying to find the mode brackets of items being sold at different locations.

I have four measures that can each equal the values of 0, 1000, 5000, 10,000, 20,000, 30,000, or 40,000.

(4 measures with 7 possible results)

I have seen several responses on how to calculate the mode of a column or one measure, but have not found one that uses multiple measures.

I have them in measures because they are calculated results being displayed in a matrix.

PBI mode.jpg

The mode for Item A should be 1,000 (biased toward the higher bracket) and Item B should be 0.

Any help would be much appreciated!

Thanks!

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

I think I got it to work.
First find any matching pairs then find any second matching pairs.  Since you only have 4 items the only thing that would beat a matched pair is a higher matched pair.  If you have any matched pair that will beat any single so I find the highest pair and if there is no pair find the highest value by comapring 2 then feeding that to the next compare and getting the max again.

Mode Measure = 
VAR N = [North]
VAR S = [South]
VAR E = [East]
VAR W = [West]

VAR FirstDouble = IF ( N = S || N = E || N = W, N )
VAR SecondDouble = IF ( S = E || S = W, S )
VAR ThirdDouble = IF ( E = W, E )
VAR MaxDouble = MAX ( MAX ( FirstDouble, SecondDouble ), ThirdDouble )

VAR FirstSingle = MAX ( N, S )
VAR SecondSingle = MAX ( FirstSingle, E )
VAR ThirdSingle = MAX ( SecondSingle, W )

VAR Result = IF( ISBLANK ( MaxDouble ), ThirdSingle, MaxDouble)

RETURN Result

*Fixed one error and change the original measures to pull to variables so they don't have to calc multiple times.

View solution in original post

3 REPLIES 3
jdbuchanan71
Super User
Super User

I think I got it to work.
First find any matching pairs then find any second matching pairs.  Since you only have 4 items the only thing that would beat a matched pair is a higher matched pair.  If you have any matched pair that will beat any single so I find the highest pair and if there is no pair find the highest value by comapring 2 then feeding that to the next compare and getting the max again.

Mode Measure = 
VAR N = [North]
VAR S = [South]
VAR E = [East]
VAR W = [West]

VAR FirstDouble = IF ( N = S || N = E || N = W, N )
VAR SecondDouble = IF ( S = E || S = W, S )
VAR ThirdDouble = IF ( E = W, E )
VAR MaxDouble = MAX ( MAX ( FirstDouble, SecondDouble ), ThirdDouble )

VAR FirstSingle = MAX ( N, S )
VAR SecondSingle = MAX ( FirstSingle, E )
VAR ThirdSingle = MAX ( SecondSingle, W )

VAR Result = IF( ISBLANK ( MaxDouble ), ThirdSingle, MaxDouble)

RETURN Result

*Fixed one error and change the original measures to pull to variables so they don't have to calc multiple times.

Artfully done sir. Thank you!

Cmcmahan
Resident Rockstar
Resident Rockstar

Should be doable if you follow this post and use a mode calculation instead of a median: https://community.powerbi.com/t5/Desktop/How-to-calculate-a-median-across-measures/td-p/154949

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.