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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Sorting the share holder name which maximum date (3/11/2022) are shows the higher shareholding value

 

HI, 

 

can someone advice how can i get the result...  I want to sort the share holder name which maximum date (3/11/2022) are showing the higher shareholding value than minimum date (2/9/2022). if let say the DAX code requires hope some one can help.Thank Youphoto1668159062.jpeg

 

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

You can create a new table with the code below:

 

MaxTable =
ADDCOLUMNS(
    VALUES(Data[Holder_Name]),
    "Date",
    VAR CurrentName = Data[Holder_Name]
    VAR MaxAmount = MAXX ( FILTER (Data,  Data[Holder_Name] = CurrentName), Data[Sum Shareholding])
    VAR MaxDate =
        CALCULATETABLE (
            VALUES(Data[Date]),
            Data[Sum Shareholding] = MaxAmount
        )
    RETURN MaxDate,
    "Amount",
    VAR CurrentName = Data[Holder_Name]
    VAR MaxAmount = MAXX ( FILTER (Data,  Data[Holder_Name] = CurrentName), Data[Sum Shareholding])
    RETURN MaxAmount
)

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

Do you want to get the rows which the value with maximum date is higher than the one on minimum date, right? If yes, I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a measure as below:

Flag = 
VAR _selholder =
    SELECTEDVALUE ( 'Table'[Holder_Name] )
VAR _seldate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR _mindate =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Holder_Name] = _selholder )
    )
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Holder_Name] = _selholder )
    )
VAR _mindvalue =
    CALCULATE (
        SUM ( 'Table'[Sum Shareholding] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Holder_Name] = _selholder
                && 'Table'[Date] = _mindate
        )
    )
VAR _maxdvalue =
    CALCULATE (
        SUM ( 'Table'[Sum Shareholding] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Holder_Name] = _selholder
                && 'Table'[Date] = _maxdate
        )
    )
RETURN
    IF ( _maxdvalue >= _mindvalue && _seldate = _maxdate, 1, 0 )

2. Create a table visual and apply the visual-level filter with the condition(Flag is 1)

yingyinr_1-1668413527705.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

FreemanZ
Super User
Super User

You can create a new table with the code below:

 

MaxTable =
ADDCOLUMNS(
    VALUES(Data[Holder_Name]),
    "Date",
    VAR CurrentName = Data[Holder_Name]
    VAR MaxAmount = MAXX ( FILTER (Data,  Data[Holder_Name] = CurrentName), Data[Sum Shareholding])
    VAR MaxDate =
        CALCULATETABLE (
            VALUES(Data[Date]),
            Data[Sum Shareholding] = MaxAmount
        )
    RETURN MaxDate,
    "Amount",
    VAR CurrentName = Data[Holder_Name]
    VAR MaxAmount = MAXX ( FILTER (Data,  Data[Holder_Name] = CurrentName), Data[Sum Shareholding])
    RETURN MaxAmount
)
Anonymous
Not applicable

the result showing error 😅. btw TQVM

daXtreme
Solution Sage
Solution Sage

// measure 1

[Date with Highest Value] =
// Works even if there are many
// companies visible. It'll then
// return the date for which the
// value is the highest among all
// the values visible for the selected
// companies. If one company is visible,
// you get what you've asked for. If
// you don't want this behaviour, you can
// always wrap this into an IF conditional
// logic.
var Output = 
    MAXX(
        topn(
            1,
            T,
            // The combination of these three fields
            // should be unique. Then this function
            // will return at most 1 row.
            T[Sum Shareholding],
            desc,
            T[Date],
            desc,
            T[Holder_Name],
            asc
        ),
        T[Date]
    )
return
    Output
    
// measure 2

[Total Sum Shareholding] =
var Output = 
    SUMX(
        topn(
            1,
            T,
            T[Sum Shareholding],
            desc,
            T[Date],
            desc,
            T[Holder_Name],
            asc
        ),
        T[Sum Shareholding]
    )
return
    Output

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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