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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

MEDIANX on the previous rows and FILTER that doesn’t seem to work with ALLEXCEPT

Hello,
I have a slight problem…
I have a table of products bought and the corresponding quantities. My goal is to predict (roughly) what will the next quantities I will buy… So I have made a measure that calculate the median of the quantities bought during the previous days to compare with the real value…

I made a simpler model to sort out all this…
The problem is that my measure works well when I consider just one product.

The visual:

median_apple.PNG

The measure:

 

_median_apple =
VAR Current_date = MIN('Apple'[Date])

RETURN
VAR median_result =
    MEDIANX(
        FILTER(
            ALLEXCEPT('Apple', Apple[Label]),
            AND('Apple'[Date] < Current_date,
                'Apple'[Quantity] > 0
            )

        ),
        'Apple'[Quantity]
    )
RETURN
    IF(median_result = BLANK(),
    " ",
    median_result
    )
 
However, when I add another product in my table, I don’t get the right results…
median_apple_pear.PNG
The first line when “Pear” appears in the column “Label” should be left blank.
And it’s not the right result anyway…
Here’s the measure for the last table:
 
_median_apple_pear =
VAR Current_date = MIN('Apple-Pear'[Date])

RETURN
VAR median_result =
    MEDIANX(
        FILTER(
            ALLEXCEPT('Apple-Pear', 'Apple-Pear'[Label]),
            AND('Apple-Pear'[Date] < Current_date,
                'Apple-Pear'[Quantity] > 0
            )

        ),
        'Apple-Pear'[Quantity]
    )
RETURN
    IF(median_result = BLANK(),
    " ",
    median_result
    )
 
Shouldn’t the ALLEXCEPT filter the rows with the corresponding labels? It’s like it’s doing nothing.
Thank you for taking a look on my problem…
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,@Anonymous 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1718765359447.png

2. Below are the measure I've created for your needs:

Measure = 
var cc=CALCULATE(MEDIAN('Apple-Pear'[Quantity]),FILTER(ALLSELECTED('Apple-Pear'),'Apple-Pear'[Label]=MAX('Apple-Pear'[Label])&&'Apple-Pear'[Date]<MAX('Apple-Pear'[Date])))
RETURN IF(cc=BLANK()," ",cc)

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1718765402473.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

2 REPLIES 2
Anonymous
Not applicable

Hi,@Anonymous 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1718765359447.png

2. Below are the measure I've created for your needs:

Measure = 
var cc=CALCULATE(MEDIAN('Apple-Pear'[Quantity]),FILTER(ALLSELECTED('Apple-Pear'),'Apple-Pear'[Label]=MAX('Apple-Pear'[Label])&&'Apple-Pear'[Date]<MAX('Apple-Pear'[Date])))
RETURN IF(cc=BLANK()," ",cc)

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1718765402473.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

Anonymous
Not applicable

It is indeed the results I wanted!

I have yet to understand why it didn’t work with my solution and how it works with yours…

Thank you very much. 🙂

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.