Search code examples
nullssasmdx

How can remove the null values?


How can I remove the null values in the bottomcount, ie. i only want to see the products with actually sold units, I have tried with nonempty and non empty without success.

with
member [Measures].[Amount Sold] as
    ([Measures].[Internet Sales Amount]),
format_string = "currency"

select {[Measures].[Amount Sold]}
on columns,
bottomcount(
order(

{[Product].[Product].Members},
([Measures].[Amount Sold]), bdesc),
5 )on rows

Solution

  • You could filter [Product].Members using NOT ISEMPTY() to exclude all the empty values, and then bottomcount the filtered set.

    with member [Measures].[Amount Sold] as
        ([Measures].[Internet Sales Amount]),
        format_string = "currency"
    select 
        {[Measures].[Amount Sold]} on columns,
        order(
            bottomcount(
                filter({[Product].[Product].Members}, NOT ISEMPTY([Measures].[Amount Sold])),
                5,
                [Measures].[Amount Sold]),
            [Measures].[Amount Sold], bdesc) on rows
    from [Adventure Works]
    

    Note that BottomCount() will do an ascending, break-hierarchies sort, so you need to do the Order() on top of it if you want descending order.