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
OmarSaleh
Helper I
Helper I

SUMMERIZE with distinct values and condition

Hello 

 

Is there anyway to create a new table from an existing one taking distict values from one colum with max value of another one?

 

Table is something like this: 

OmarSaleh_0-1623703290113.png

 

 

The result table should contain distict ID values in column ID, with the Max value in column Value. 

 

OmarSaleh_1-1623703322351.png

 

Any idea? 

 

Thanks!

 

1 ACCEPTED SOLUTION
v-xulin-mstf
Community Support
Community Support

Hi @OmarSaleh,

 

You use Maxx function:

 

Measure = 
var _max=
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[ID]=MAX('Table'[ID])
    ),
    'Table'[Value]
)
return
IF(
    _max=MAX('Table'[Value]),
    1,
    0)

 

Here is the output:

vxulinmstf_0-1624505156657.png

 

The pbix is attached.

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

 

View solution in original post

4 REPLIES 4
v-xulin-mstf
Community Support
Community Support

Hi @OmarSaleh

 

Is your issue solved?

If the issue has been solved, please adopt the solution to help others.

If you still have some question, please don't hesitate to let me known.‌‌

😉

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

 

 

v-xulin-mstf
Community Support
Community Support

Hi @OmarSaleh,

 

You use Maxx function:

 

Measure = 
var _max=
MAXX(
    FILTER(
        ALL('Table'),
        'Table'[ID]=MAX('Table'[ID])
    ),
    'Table'[Value]
)
return
IF(
    _max=MAX('Table'[Value]),
    1,
    0)

 

Here is the output:

vxulinmstf_0-1624505156657.png

 

The pbix is attached.

 

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

 

Pragati11
Super User
Super User

Hi @OmarSaleh ,

 

You can write a DAX as follows for creating a new table:

groupedTable = SUMMARIZE(tablename, tablename[ID], "Date", MAX(tablename[Date]), "Value", MAX(tablename[Value])

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

@OmarSaleh, note that this takes the max of Date and Value independently, which could potentially produce rows that aren't from your original table if the maximal values for that ID occur in separate rows.

 

A different approach that pulls the Date corresponding to the maximal Value uses two steps:

ADDCOLUMNS (
    ADDCOLUMNS (
        DISTINCT ( Table1[ID] ),
        "Value", CALCULATE ( MAX ( Table1[Value] ) )
    ),
    "Date", CALCULATE ( MAX ( Table1[Date] ), Table1[Value] = EARLIER ( [Value] ) )
)

This pulls the date corresponding to the maximal value rather than the maximal date for that ID.

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.