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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
travellers_173
New Member

Group based on max occurance of text field instead of max considering alphabetical letter

Hi,

 

New to Power BI and stuck on this. I am trying to get the max occured value while grouping the data for each month. In the below data for Jan Closed is more so I want the result group for ABC(Name), 1-Jan-23 (Month), Closed. But when I did a group by in Power query it is saying Open for Jan since O is max alphabetically. How to achieve this in Power Query (M) and no in Dax?

 

NameMonthStatus
ABC01-Jan-23Closed
ABC01-Jan-23Closed
ABC01-Jan-23Closed
ABC01-Jan-23Closed
ABC01-Jan-23Open
ABC01-Feb-23Open
ABC01-Feb-23Open
ABC01-Feb-23Closed
ABC01-Feb-23Closed
ABC01-Feb-23Closed
ABC01-Feb-23Open
ABC01-Mar-23 
ABC01-Mar-23 
ABC01-Mar-23 
2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @travellers_173 ,

vyangliumsft_0-1677563225642.png

 

Here are the steps you can follow:

1. Create calculated column.

Flag =
COUNTX(
    FILTER(ALL('Table'),
'Table'[Name]=EARLIER('Table'[Name])&&MONTH('Table'[Month])=MONTH(EARLIER('Table'[Month]))&&'Table'[Status]=EARLIER('Table'[Status])),
    [Name])

2. Create calculated table.

Table 2 =
DISTINCT(
FILTER(
    'Table',   
    'Table'[Flag]=
    MAXX(        FILTER(ALL('Table'),'Table'[Name]=EARLIER('Table'[Name])&&MONTH('Table'[Month])=MONTH(EARLIER('Table'[Month]))),[Flag])))

3. Result:

vyangliumsft_1-1677563225644.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

lbendlin
Super User
Super User

lbendlin_0-1676850301340.png

 

Please indicate what should happen in case of a tie (February)  and in case of missing status (March)

 

Note that Power Query is case sensitive and does not trim values.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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