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
RiskyBiscuts
Advocate I
Advocate I

How does one filter out zeros/nulls when using MEDIANX and FILTER combo?

This has been a real headache, I have been trying to create a calculated column (has to be a calc. col.) that gets me the median value for each "UnitType". The challenge I am encountering is that calculation is accounting for the 0 or null values in the "Dev/Known" column, so the median is either inaccurate or I get a 0 value for an answer (due to all the zeros and nulls). What can I do to get around this?

 

Median Dev/Known =
MEDIANX
(
     FILTER(
         ALL('Project Data'),[UnitType] = EARLIER([UnitType])),
[Dev/Known]
)
 
I have part of the table below. In excel this is rather easy to do, PBI, not so much.
 

Table to be analyzedTable to be analyzed

 

Thank you!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Will this work?

 

Median Dev/Known =
VAR varUnitType = [UnitType]
RETURN
    MEDIANX(
        FILTER(
            ALL( 'Project Data' ),
            [UnitType] = varUnitType
                && NOT [Dev/Known]
                    IN {
                        0,
                        BLANK()
                    }
        ),
        [Dev/Known]
    )

 

It will filter the table to exclude rows where the Dev/Known field is zero or null. 
I also got rid of the Earlier function. Pet peeve of mine since variables came out. 😉



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

3 REPLIES 3
edhans
Super User
Super User

Will this work?

 

Median Dev/Known =
VAR varUnitType = [UnitType]
RETURN
    MEDIANX(
        FILTER(
            ALL( 'Project Data' ),
            [UnitType] = varUnitType
                && NOT [Dev/Known]
                    IN {
                        0,
                        BLANK()
                    }
        ),
        [Dev/Known]
    )

 

It will filter the table to exclude rows where the Dev/Known field is zero or null. 
I also got rid of the Earlier function. Pet peeve of mine since variables came out. 😉



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

This is exactly what I was looking for! Thank you!

Great @RiskyBiscuts - glad to help.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.