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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jessica_17
Helper IV
Helper IV

Max Column value based on another columns matching value

I have a table , where I want max month name where AL=CL=CU

In this example September is the month which I want, regardless of any department

DepartmentMonthsACCLCU
2February105105105
2March245245245
2April500500500
2May745745745
2June990990990
2July105010501050
2August200020002000
2September210021002100
2October256023432560
2November340035663045
2December460037894786
2January500046785678
40February105105105
40March245245245
40April500500500
40May745745745
40June990990990
40July105010501050
40August200020002000
40September210021002100
40October256023432560
40November340035663045
40December460037894786
40January500046785678

 

Can anyone please help me with this? as I am not able to get the max month like this anyhow. 

4 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@Jessica_17 

pls try this

Measure = 
VAR tbl=ADDCOLUMNS('Table',"check",if('Table'[AC]='Table'[CL]&&'Table'[AC]='Table'[CU],1,0))
return FORMAT(maxx(FILTER(tbl,[check]=1),'Table'[Months]),"mmmm")

11.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Ahmedx
Super User
Super User

HI @ryan_mayu 

Thanks It worked for me.

View solution in original post

pls try this

Screenshot_1.png

 

Measure = 
VAR _tbl = TOPN(1,
 SELECTCOLUMNS(
        FILTER(
            ADDCOLUMNS(
           'Table',
                "Flag", INT( MIN( CALCULATE( MIN( 'Table'[AC] ) ), CALCULATE( MIN( 'Table'[CL] ) ) ) = CALCULATE( MIN( 'Table'[CU] ) ) )
            ),
            [Flag] = 1
        ),
        "@Month", 'Table'[Months],
        "@AC", 'Table'[AC]
    ),ABS([@AC]))
    RETURN 
    MAXX(_tbl,[@Month])

 

 

View solution in original post

13 REPLIES 13
Ahmedx
Super User
Super User

pls try this

Screenshot_1.png

HI @Ahmedx , @ryan_mayu 
If we want to create measure for same on negative numbers and for each department, how can we do that , I am not able to figure that out. Here is a sample data.

DepartmentMonthsACCLCU
2January500046785678
2December460037894786
2November340035663045
2October256023432560
2September210021002100
2August200020002000
2July105010501050
2June990990990
2May745745745
2April500500500
2March245245245
2February105105105
46February-1-1-1
46March-2-2-2
46April-3-3-3
46May-4-4-4
46June-5-5-5
46July-6-6-6
46August-7-7-7
46September-8-8-8
46October-9-10-11
46November-10-12-13
46December-14-17-15
46January-20-16-15

and the result should be different, not September?

yes, depends on data, for negative right now it is september only, as max value works differently in negative right?

I don't think I understand you but try again

HI @Ahmedx 

Suppose for this department , last matching values are -8 for september month, while using you query, it will show february, but I want september 

as in negative value we would want minimum value instead of maximum value.

Jessica_17_0-1700638836513.png

 

pls try this

Screenshot_1.png

 

Measure = 
VAR _tbl = TOPN(1,
 SELECTCOLUMNS(
        FILTER(
            ADDCOLUMNS(
           'Table',
                "Flag", INT( MIN( CALCULATE( MIN( 'Table'[AC] ) ), CALCULATE( MIN( 'Table'[CL] ) ) ) = CALCULATE( MIN( 'Table'[CU] ) ) )
            ),
            [Flag] = 1
        ),
        "@Month", 'Table'[Months],
        "@AC", 'Table'[AC]
    ),ABS([@AC]))
    RETURN 
    MAXX(_tbl,[@Month])

 

 

Hi @Ahmedx 

This worked, thank you so much for the help.

Hi @Ahmedx 

Thanks for the solution, this solution also worked for me

Ashish_Mathur
Super User
Super User

Hi,

Do you have a year column as well?  If yes, then please share the dataset with that column.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur 

There is not year column, but I got the solution from @ryan_mayu . Thanks for the help.

ryan_mayu
Super User
Super User

@Jessica_17 

pls try this

Measure = 
VAR tbl=ADDCOLUMNS('Table',"check",if('Table'[AC]='Table'[CL]&&'Table'[AC]='Table'[CU],1,0))
return FORMAT(maxx(FILTER(tbl,[check]=1),'Table'[Months]),"mmmm")

11.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




HI @ryan_mayu 

Thanks It worked for me.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.