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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
spart_1337
Frequent Visitor

Finding the median and top quartile of a category based on figures from another DAX measure

Context

I have a table containing a list of portfolios, their monthly returns and category.

Table 1

Portfolio DateMonthly ReturnCategory
A31-Jan-241.00%X
A29-Feb-240.50%X
B31-Jan-240.20%X
B29-Feb-240.30%X
C31-Jan-242.00%Y
C29-Feb-242.50%Y
D31-Jan-24-0.10%Y
D29-Feb-24-0.80%Y

 

Using the data Table 1, I dynamically calculate the annualised return of each portfolio according to the dates selected in my date slicer with the following DAX measure:

 

 

 

Return_Annualised = 
VAR DateSlicerStart = MIN('Table 1'[Date])
VAR DateSlicerEnd = MAX('Table 1'[Date])
VAR AnnualisationFactor = DIVIDE(DateSlicerEnd - EOMONTH(DateSlicerStart, -1), 365)

RETURN
    POWER(PRODUCTX('Table 1', 1 + 'Table 1'[Monthly Return]), 1/AnnualisationFactor)-1

 

 

 

This gives me the following result:

spart_1337_1-1716094461541.png

My Question

From this result, how can I get the:

1) Median annualised return for each category?

2) Top quartile annualised return (if there are 4 or more data points) for each category, if less than 4 data points, return blank?

 

Example of desired output:

spart_1337_0-1716096043446.png

 

Appreciate any assistance.

 

 

1 ACCEPTED SOLUTION
spart_1337
Frequent Visitor

Solved using the following for median:

 

 

 

Median_Annualised_Return = 
CALCULATE(
    MEDIANX(
        SUMMARIZE(
            'Table 1',
            'Table 1'[Portfolio],
            'Table 1'[Category],
            "AnnualisedReturn", [Return_Annualised]
        ),
        [AnnualisedReturn]
    ),
    ALLEXCEPT('Table 1', 'Table 1'[Category])
)

 

 

 

 

For top quartile:

 

 

 

TopQuartile_Annualised_Return = 
VAR AnnualisedReturns = 
CALCULATETABLE(
    ADDCOLUMNS(
        SUMMARIZE(
            'Table 1',
            'Table 1'[Portfolio],
        ),
        "AnnualisedReturn",[Return_Annualised]
    ),
    ALLEXCEPT('Table 1', 'Table 1'[Category])
)
VAR ReturnCount = COUNTROWS(AnnualisedReturns)
VAR TopQuartileReturn =
IF(
    ReturnCount >=4,
    PERCENTILEX.EXC(AnnualisedReturns, [AnnualisedReturn], 0.75),
    BLANK()
)

RETURN TopQuartileReturn

 

 

 

 

View solution in original post

3 REPLIES 3
spart_1337
Frequent Visitor

Solved using the following for median:

 

 

 

Median_Annualised_Return = 
CALCULATE(
    MEDIANX(
        SUMMARIZE(
            'Table 1',
            'Table 1'[Portfolio],
            'Table 1'[Category],
            "AnnualisedReturn", [Return_Annualised]
        ),
        [AnnualisedReturn]
    ),
    ALLEXCEPT('Table 1', 'Table 1'[Category])
)

 

 

 

 

For top quartile:

 

 

 

TopQuartile_Annualised_Return = 
VAR AnnualisedReturns = 
CALCULATETABLE(
    ADDCOLUMNS(
        SUMMARIZE(
            'Table 1',
            'Table 1'[Portfolio],
        ),
        "AnnualisedReturn",[Return_Annualised]
    ),
    ALLEXCEPT('Table 1', 'Table 1'[Category])
)
VAR ReturnCount = COUNTROWS(AnnualisedReturns)
VAR TopQuartileReturn =
IF(
    ReturnCount >=4,
    PERCENTILEX.EXC(AnnualisedReturns, [AnnualisedReturn], 0.75),
    BLANK()
)

RETURN TopQuartileReturn

 

 

 

 

Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.


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

Hi @Ashish_Mathur I would be more than happy to share the file if there was an option to attach it to the post directly. If any of you folks at Microsoft are reading this it would be great if you could add this feature.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.