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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
awalsh
Helper I
Helper I

Calculating Mode & Number of items for Mode

Hi, 

 

1. I have a Dax formula that is calculating the Mode, however, it fails to account for when there is no mode (all values appearing once) it just lists the smallest value as the mode. Is there a formula that would identify situations where there is no mode? 

 

2. Also, is it possible to have a formula count the number of items that make up the mode? 

 

Thank you in advance! 

 

Here is the formula I'm currently using: 

 

Mode  =
MINX(
TOPN(1,
ADDCOLUMNS(
VALUES('NJ2000_LOS_Extract-All'[LOS in Months]),
"frequency", CALCULATE(COUNT('NJ2000_LOS_Extract-All'[LOS in Months]))),
[frequency],
0),
'NJ2000_LOS_Extract-All'[LOS in Months])

 

1 ACCEPTED SOLUTION

Hi, @awalsh ;

If your Mode value is a measure ,you could modify the two dax as follows:

Measure = IF(ISINSCOPE('Table'[ID]),[mea-Mode],MAX([Column]))
Measure2 = IF(ISINSCOPE('Table'[ID]),[mea-Mode],MAX([count]))

The final output is shown below:

vyalanwumsft_0-1625621059370.png

If it's not right, can you share with me .pbix without any sesentive information .
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi , @awalsh ;

According to your description, you could create column and measure as follows:

1) create a column to calculate the count .

count = CALCULATE(COUNT([Mode]),FILTER(ALL('Table'),[month]=EARLIER([month])&&[Mode]=EARLIER([Mode])))

2)create a column 

Column = 
var _a=MAXX(FILTER('Table',[month]=EARLIER([month])),[count])
var _b=MINX(FILTER('Table',[month]=EARLIER([month])),[count])
return IF(_a=_b,"N/A",IF(_a=[count],FORMAT([Mode],"General Number")))

3)create a measure

Measure = IF(ISINSCOPE('Table'[ID]),SUM([Mode]),MAX([Column]))

4)create another measure

Measure2 = IF(ISINSCOPE('Table'[ID]),SUM([Mode]),MAX([count]))

The final output is shown below:

vyalanwumsft_0-1625133769004.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much for your help. I really appreciate it. This is exactly what I'm trying to do - however, 

 

When I try to create the first two DAX columns that you provided, I'm getting an error because my Mode values are being calculated using a measure. It seems that the formula isn't allowing me to reference a measure, it's asking me for a column. 😞 Any suggestions? 

Hi, @awalsh ;

If your Mode value is a measure ,you could modify the two dax as follows:

Measure = IF(ISINSCOPE('Table'[ID]),[mea-Mode],MAX([Column]))
Measure2 = IF(ISINSCOPE('Table'[ID]),[mea-Mode],MAX([count]))

The final output is shown below:

vyalanwumsft_0-1625621059370.png

If it's not right, can you share with me .pbix without any sesentive information .
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you - should I keep the count and Column Dax the same or do I need to modify those as well? 

parry2k
Super User
Super User

@awalsh share sample data and expected output. Not fully clear what you are trying to achieve. Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi, 

 

I'm hesitant to post a sample file due to HIPAA and the nature of the data I'm working with. However, here is a screenshot with sample member ID's to help explain what I am trying to achieve. 

 

First, I want to have Power BI calculate the mode based on the "Length of Stay in Months" column for each month.

 

As you can see, for January - the formula I'm currently using worked in that it recognized that two Member IDs have a length of stay of 18 months thus, making 18 the mode for January. 

 

However, looking at February and so on, there is no mode because each Length of Stay only appears once.

 

The formula seems to be choosing the smallest Legnth of Stay for months with no mode. For example, Power BI is saying that February has a mode of 8 however, there is actually no mode that month and 8 is just the smallest Legnth of Stay for that month.  

 

My 2 questions are as follows: 

 

1. Is there any formula that can list "N/A" or something to this effect for months where there is no mode? 

 

2. For months where there is a mode, can I have Power BI calculate the number of Member ID's that make up that Mode? For example, January has a mode of 18 consisting of 2 member ID's. 

awalsh_1-1624910115965.png

 

 

Thank you for your assistance. 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.