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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Creating matrix that finds maximum for each row

Hi,

 

I am trying to create a table that shows the record quarter and value of that quarter for different categories like  sum of Sales, sum of AOI, sum of AOI%, etc. I am looking for the quarter with the maximum sum of ___ (whatever category is in question). I created a sample chart of what it should look like in Excel, but I am trying to find a way to build this in Power BI. (also included sample data to hopefully make things understandable)

 

I am able to create individual tables for each category and find the maximum for that category, but I am having a spacing issue when inserting these tables into my report. I was hoping to find a way to create one table for all categories, as the spacing for this would match the rest of the report.

 

Any and all help is appreciated! Thanks!

 

Sample ChartSample Chart

Sample DataSample Data

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression approach to get your max value.  Replace the Return with the code in the comment to get the max quarter. replace Total Sales with your measure.

 

Max Qtr =
VAR vSummary =
    ADDCOLUMNS (
        DISTINCT ( 'Date'[YearQuarter] ),
        "cSales", [Total Sales]
    )
VAR vTop1 =
    TOPN (
        1,
        vSummary,
        [cSales]
    )
RETURN
    MINX (
        vTop1,
        [cSales]
    )
//MINX(vTop1, 'Date'[YearQuarter])

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,


I think the code provided by the @mahoneypat  is a good choice, you can try it.


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

Ashish_Mathur
Super User
Super User

Hi,

Please share data in a format that can be pasted in an MS Excel file.  Also, please type numbers in place of xxx.  In the sample dataset, do you have an actual date column (instead of quarter-year)?


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

Please try this measure expression approach to get your max value.  Replace the Return with the code in the comment to get the max quarter. replace Total Sales with your measure.

 

Max Qtr =
VAR vSummary =
    ADDCOLUMNS (
        DISTINCT ( 'Date'[YearQuarter] ),
        "cSales", [Total Sales]
    )
VAR vTop1 =
    TOPN (
        1,
        vSummary,
        [cSales]
    )
RETURN
    MINX (
        vTop1,
        [cSales]
    )
//MINX(vTop1, 'Date'[YearQuarter])

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.