cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DRA885
New Member

MEDIANX missing values for dates with no data

Hello all.

 

I'm looking for some help on this DAX code:

 

 

Median Test 3 (next 3 months approved) = 
VAR MedianValueDiscipline =
    CALCULATE (
        MEDIANX (
            SUMMARIZE (
                'Actual & Forecast Project Resources',
                'Actual & Forecast Project Resources'[Work Week Ending Date],
                'Actual & Forecast Project Resources'[Capsule Descriptions.Discipline],
                "Median FTEs",
                    SUMX (
                        'Actual & Forecast Project Resources',
                        'Actual & Forecast Project Resources'[Consolidated FTEs]
                    )
            ),
            [Median FTEs]
        ),
        'Actual & Forecast Project Resources'[Final Consolidated Hours Type] = "Approved",
        DATESINPERIOD (
            'Actual & Forecast Project Resources'[Work Week Ending Date],
            MAX ( 'Date'[EndOfThisWeek] ) - 1,
            3,
            MONTH
        )
    )
RETURN
    MedianValueDiscipline

 

 

 
This is producing the following results in a matrix:
Median - next 3 months.png
Whilst this is giving the correct total value, the rows with null values are incorrect as the Median is only calculating for dates where there is a value. The rows with 'blanks' are from the field 'Actual & Forecast Project Resources'[Capsule Descriptions.Level Category]
 
My question is, how can I force zero values into the 'blanks' and obtain the correct result for each row of the matrix?
 
TIA, Ian
1 ACCEPTED SOLUTION
DRA885
New Member

solved with the following change to the Sum calculation of FTEs:

Median Test 3 (next 3 months approved) =
VAR MedianValueDiscipline =
    CALCULATE (
        MEDIANX (
            SUMMARIZE (
                'Actual & Forecast Project Resources',
                'Actual & Forecast Project Resources'[Work Week Ending Date],
                'Actual & Forecast Project Resources'[Capsule Descriptions.Discipline],
                "Median FTEs",
                    IF (
                        CALCULATE (
                            SUM ( 'Actual & Forecast Project Resources'[Consolidated FTEs] ),
                            'Actual & Forecast Project Resources'[Final Consolidated Hours Type] = "Approved"
                        ) > 0,
                        CALCULATE (
                            SUM ( 'Actual & Forecast Project Resources'[Consolidated FTEs] ),
                            'Actual & Forecast Project Resources'[Final Consolidated Hours Type] = "Approved"
                        ),
                        0
                    )
            ),
            [Median FTEs]
        ),
        DATESINPERIOD (
            'Actual & Forecast Project Resources'[Work Week Ending Date],
            MAX ( 'Date'[EndOfThisWeek] ) - 1,
            3,
            MONTH
        )
    )
RETURN
    MedianValueDiscipline

 

View solution in original post

1 REPLY 1
DRA885
New Member

solved with the following change to the Sum calculation of FTEs:

Median Test 3 (next 3 months approved) =
VAR MedianValueDiscipline =
    CALCULATE (
        MEDIANX (
            SUMMARIZE (
                'Actual & Forecast Project Resources',
                'Actual & Forecast Project Resources'[Work Week Ending Date],
                'Actual & Forecast Project Resources'[Capsule Descriptions.Discipline],
                "Median FTEs",
                    IF (
                        CALCULATE (
                            SUM ( 'Actual & Forecast Project Resources'[Consolidated FTEs] ),
                            'Actual & Forecast Project Resources'[Final Consolidated Hours Type] = "Approved"
                        ) > 0,
                        CALCULATE (
                            SUM ( 'Actual & Forecast Project Resources'[Consolidated FTEs] ),
                            'Actual & Forecast Project Resources'[Final Consolidated Hours Type] = "Approved"
                        ),
                        0
                    )
            ),
            [Median FTEs]
        ),
        DATESINPERIOD (
            'Actual & Forecast Project Resources'[Work Week Ending Date],
            MAX ( 'Date'[EndOfThisWeek] ) - 1,
            3,
            MONTH
        )
    )
RETURN
    MedianValueDiscipline

 

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.

Top Solution Authors
Top Kudoed Authors