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
Iamnvt
Continued Contributor
Continued Contributor

Dax to show the year with max value

I have a table below:

 

ProductY1Y2Y3
A123
B111
C333

 

need the result to show the Y with max total of all product (which is Y3: total = 10)

Expected result:

 

ProductY3
A3
B1
C3
Total10

 

Thank you

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Iamnvt ,

According to your description, I have two methods.

Method1

1.Create a calculated column in the table.

MAX-Y = 
VAR _SUMY1=SUM('Table'[Y1])
VAR _SUMY2=SUM('Table'[Y2])
VAR _SUMY3=SUM('Table'[Y3])
VAR _MAXsum=MAXX({_SUMY1,_SUMY2,_SUMY3},[Value])
RETURN
SWITCH(TRUE(),
_SUMY1=_MAXsum,'Table'[Y1],
_SUMY2=_MAXsum,'Table'[Y2],
_SUMY3=_MAXsum,'Table'[Y3])

vkalyjmsft_0-1639539229547.png

2.If you want to show the year name, you can then create another measure.

MAX Year = 
VAR _SUMY1=SUM('Table'[Y1])
VAR _SUMY2=SUM('Table'[Y2])
VAR _SUMY3=SUM('Table'[Y3])
VAR _MAXsum=MAXX({_SUMY1,_SUMY2,_SUMY3},[Value])
RETURN
SWITCH(TRUE(),
_SUMY1=_MAXsum,"Y1",
_SUMY2=_MAXsum,"Y2",
_SUMY3=_MAXsum,"Y3")

vkalyjmsft_1-1639539340591.png

Method2

1.Select Y1,Y2,Y3 at the same time, and then click unpivot columns, then get three columns.

vkalyjmsft_2-1639539618643.png

vkalyjmsft_3-1639539627826.png

2.Cteate a new column to calculate the max total value.

Column =
SUMX (
    FILTER ( ALL ( 'Table (2)' ), 'Table (2)'[Year] = MAX ( 'Table (2)'[Year] ) ),
    'Table (2)'[Value]
)

3.Create a measure.

Check =
VAR _SUM =
    SUMX (
        FILTER ( ALL ( 'Table (2)' ), 'Table (2)'[Year] = MAX ( 'Table (2)'[Year] ) ),
        'Table (2)'[Value]
    )
RETURN
    IF ( _SUM = MAX ( 'Table (2)'[Column] ), 1, 0 )

4.Put the measure in the visual filter and select it is 1, get the expected result.

vkalyjmsft_4-1639539897957.png

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

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

4 REPLIES 4
v-yanjiang-msft
Community Support
Community Support

Hi @Iamnvt ,

According to your description, I have two methods.

Method1

1.Create a calculated column in the table.

MAX-Y = 
VAR _SUMY1=SUM('Table'[Y1])
VAR _SUMY2=SUM('Table'[Y2])
VAR _SUMY3=SUM('Table'[Y3])
VAR _MAXsum=MAXX({_SUMY1,_SUMY2,_SUMY3},[Value])
RETURN
SWITCH(TRUE(),
_SUMY1=_MAXsum,'Table'[Y1],
_SUMY2=_MAXsum,'Table'[Y2],
_SUMY3=_MAXsum,'Table'[Y3])

vkalyjmsft_0-1639539229547.png

2.If you want to show the year name, you can then create another measure.

MAX Year = 
VAR _SUMY1=SUM('Table'[Y1])
VAR _SUMY2=SUM('Table'[Y2])
VAR _SUMY3=SUM('Table'[Y3])
VAR _MAXsum=MAXX({_SUMY1,_SUMY2,_SUMY3},[Value])
RETURN
SWITCH(TRUE(),
_SUMY1=_MAXsum,"Y1",
_SUMY2=_MAXsum,"Y2",
_SUMY3=_MAXsum,"Y3")

vkalyjmsft_1-1639539340591.png

Method2

1.Select Y1,Y2,Y3 at the same time, and then click unpivot columns, then get three columns.

vkalyjmsft_2-1639539618643.png

vkalyjmsft_3-1639539627826.png

2.Cteate a new column to calculate the max total value.

Column =
SUMX (
    FILTER ( ALL ( 'Table (2)' ), 'Table (2)'[Year] = MAX ( 'Table (2)'[Year] ) ),
    'Table (2)'[Value]
)

3.Create a measure.

Check =
VAR _SUM =
    SUMX (
        FILTER ( ALL ( 'Table (2)' ), 'Table (2)'[Year] = MAX ( 'Table (2)'[Year] ) ),
        'Table (2)'[Value]
    )
RETURN
    IF ( _SUM = MAX ( 'Table (2)'[Column] ), 1, 0 )

4.Put the measure in the visual filter and select it is 1, get the expected result.

vkalyjmsft_4-1639539897957.png

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

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

 

parry2k
Super User
Super User

@Iamnvt what @amitchandak suggest in the first part, unpivot the table, it will get you two columns Attribute and Value, rename it as you see fit and then just you need a sum measure

 

Sum = SUM ( Table[Value] )

 

to visualize, add matrix visual:

 

- product on rows

- attribute on columns

- measure on value

 

and you can filter on any year, in this case you will filer where attribute value is = Y3 so that the matrix visual only shows y3 

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  



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.

amitchandak
Super User
Super User

@Iamnvt ,

 

Unpivot the table Year(Y) will come on rows
rename that as Year
then create this measure in dax

measure =
var _max = Maxx(allselected(Table), Table[Year])
return
Sumx(filter(Table, Table[Year] = _max), Table[Value])

 

https://radacad.com/pivot-and-unpivot-with-power-bi
Transpose : https://yodalearning.com/tutorials/power-query-helps-transposing-data/

Iamnvt
Continued Contributor
Continued Contributor

@amitchandak 
How about if the _max value is at Y2? I need to filter the year with TOTAL MAX value.

Thanks

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.