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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
lafakios
Helper I
Helper I

Create a Calculated table with distinct values (rows filtered based on MAX in a column)

Hi,

 

I have a table similar to the below

 

Table_1

 

IDNameQuantity1Quantity2
10001000.a2043
10001000.b1535
10001000.c2555
10011001.a3472
10011001.b2396
10011001.c5313
10021002.a6538
10021002.b4333
10021002.c2319

 

and I would like to create a calculated table with the same columns based on the dinstict values of ID.

Every row in the new table should have a dinstict ID value and the values of the other columns of that row which has the highest Quantity2 value. The calculated table should be like the below.

 

Table_2

 

IDNameQuantity1Quantity2
10001000.c2555
10011001.b2396
10021002.a6538

 

By using the below DAX formula, I can only create a table with the dinstic ID and the max Quality2 values.

Is there a way to create a table including also the Name and Quantity1 values?
 
Table_2 = GENERATE(DISTINCT('Table_1'[ID]),
SUMMARIZE('Table_1',
"Quantity2", CALCULATE(MAX('Table_1'[Quantity2]))))

 

Thanks in advance for your help.

 

Regards,

Akis

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @lafakios ,

Please try the following methods and check if they can solve your problem:

1.Create the simple table.

vjiewumsft_0-1709621080452.png

2.Create the new measure in the Table.

vjiewumsft_2-1709621184907.png

 

 

Quan2 = 
VAR _MAX = CALCULATE(MAX('Table'[Quantity2]), ALLEXCEPT('Table','Table'[ID]))
RETURN
IF(MAX([Quantity2]) = _MAX, 1, 0)

 

3.Create the new Table2.

 

Table 2 = 
SUMMARIZE(FILTER('Table', [Quan2] = 1), 'Table'[ID], 'Table'[Name], 'Table'[Quantity1], 'Table'[Quantity2])

 

4.The Table 2 visual is shown below.

vjiewumsft_1-1709621137173.png

 

Best Regards,

Wisdom 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

4 REPLIES 4
Anonymous
Not applicable

Hi @lafakios ,

Please try the following methods and check if they can solve your problem:

1.Create the simple table.

vjiewumsft_0-1709621080452.png

2.Create the new measure in the Table.

vjiewumsft_2-1709621184907.png

 

 

Quan2 = 
VAR _MAX = CALCULATE(MAX('Table'[Quantity2]), ALLEXCEPT('Table','Table'[ID]))
RETURN
IF(MAX([Quantity2]) = _MAX, 1, 0)

 

3.Create the new Table2.

 

Table 2 = 
SUMMARIZE(FILTER('Table', [Quan2] = 1), 'Table'[ID], 'Table'[Name], 'Table'[Quantity1], 'Table'[Quantity2])

 

4.The Table 2 visual is shown below.

vjiewumsft_1-1709621137173.png

 

Best Regards,

Wisdom Wu

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

 

 

 

 

 

 

 

 

 

Hi,

 

This solution worked, thank you all for your support!!

 

Regards,

Akis

Greg_Deckler
Community Champion
Community Champion

@lafakios Try:

Table_2 = 
ADDCOLUMNS(
    SUMMARIZE( 'Table_1', [ID], "Quantity2", MAX('Table_1'[Quantity2] )),
    "Quantity1", MAXX(FILTER('Table_1', [ID] = EARLIER([ID]) && [Quantity2] = EARLIER([Quantity2])), [Quantity1]),
    "Name", MAXX(FILTER('Table_1', [ID] = EARLIER([ID]) && [Quantity2] = EARLIER([Quantity2])), [Name])
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks for the advice.

I tried the above DAX formula and managed to get a table similar to what I was after.

 

After doing some investigation, I observed that the generated table does not include all rows as expected.

In other words, the generated table might miss for instance the last row 

 

"1002 1002.a   65  38"

 

The investigation I did was based on a comparison done between Table.2 and a Table.1 visual.

The Matrix visual uses in Values measures like the below:

 

CALCULATE (
SELECTEDVALUE ( 'Table_1'[Quantity1] ),
FILTER ( ALL ( 'Table_1'[Quantity2] ), 'Table_1'[Quantity2] = MAX ( 'Table_1'[Quantity2] ) )

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors