Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

DAX filter not working

I am trying to display the number of customers that fall within each revenue range.

 

This is the code I have right now. However, the filter does not seem to be working. 

Rev Range =
SWITCH (
    SELECTEDVALUE ( 'RangeTable'[Range] ),
    "< $0",
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[CustID] ),
            FILTER ( 'Table', [Rev_Current YTD] < 0 )
        ),
    "$0 to $100",
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[CustID] ),
            FILTER ( 'Table', [Rev_Current YTD] > 0 && [Rev_Current YTD] <= 100 )
        ),
    "$101 to $500",
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[CustID] ),
            FILTER ( 'Table', [Rev_Current YTD] > 100 && [Rev_Current YTD] <= 500 )
        ),
    "$501 to $1000",
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[CustID] ),
            FILTER ( 'Table', [Rev_Current YTD] > 500 && [Rev_Current YTD] <= 1000 )
        ),
    "$1001 to $1500",
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[CustID] ),
            FILTER ( 'Table', [Rev_Current YTD] > 1000 && [Rev_Current YTD] <= 1500 )
        ),
    "> $1500"
)
 
This is what my visualisation in PBI shows.
    

 

and this is my visualisation if it helps:

 

 

11 Replies

  • DimaMD's avatar
    DimaMD
    Solution Sage

    hi Anonymous  Provide a dummy file for testing.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello DimaMD , there is no button for me to upload the files and filesharing webs are blocked by my company laptop. Would it help if I screenshot the data?

    • DimaMD's avatar
      DimaMD
      Solution Sage

      Anonymous you can put data here as text,
      also provide the measures used in the condition

      • Anonymous's avatar
        Anonymous
        Not applicable
        Hello DimaMD ,
        *To sum total revenue
        Rev_Current YTD = sum('Table'[Revenue])

         

        Raw data:

        CustIDCustNameRevenueDate
        1001Netflix400Oct-22
        1001Netflix117Oct-22
        1001Netflix98Dec-22
        1001Netflix2345Nov-22
        1001Netflix90Oct-22
        1002Spotify277Sep-22
        1002Spotify2455Nov-22
        1002Spotify104Oct-22
        1002Spotify654Nov-22
        1002Spotify205Sep-22
        1003Disney8Oct-22
        1003Disney53Oct-22
        1003Disney853Sep-22
        1003Disney209Sep-22
        1003Disney113Oct-22
        1004Instagram195Nov-22
        1004Instagram181Sep-22
        1004Instagram297Sep-22
        1004Instagram124Sep-22
        1004Instagram283Oct-22
        1004Instagram45Oct-22
        1005Facebook239Sep-22
        1005Facebook113Nov-22
        1005Facebook231Oct-22
        1005Facebook124Nov-22
        1005Facebook156Dec-22
        1006Google157Dec-22
        1006Google61Dec-22
        1006Google264Dec-22
        1006Google175Sep-22
        1006Google289Dec-22
        1008Cloversoft192Dec-22
        1008Cloversoft118Dec-22
        1008Cloversoft214Sep-22
        1008Cloversoft93Oct-22
        1008Cloversoft277Sep-22
        1009TWG21Nov-22
        1009TWG27Nov-22
        1009TWG295Nov-22
        1009TWG152Nov-22
        1009TWG3Dec-22
        1009TWG271Dec-22
        1009TWG18Sep-22
        1011KFC29Dec-22
        1011KFC222Oct-22
        1011KFC227Sep-22
        1011KFC71Dec-22
        1012Long John Silver78Nov-22
        1012Long John Silver41Dec-22
        1012Long John Silver60Nov-22
        1012Long John Silver70Dec-22
        1013Burger King95Sep-22
        1013Burger King300Dec-22
        1013Burger King63Sep-22
        1013Burger King8055Nov-22
        1014Microsoft216Dec-22
        1014Microsoft222Dec-22
        1014Microsoft270Sep-22
        1014Microsoft15Sep-22
        1015Acer4Nov-22
        1015Acer220Nov-22
        1015Acer26Dec-22
        1015Acer151Dec-22
        1015Acer259Nov-22
        1016Dell124Nov-22
        1016Dell145Sep-22
        1016Dell215Dec-22
        1016Dell79Nov-22
        1016Dell18Nov-22
        1017Lenovo279Oct-22
        1017Lenovo584Dec-22
        1017Lenovo51Nov-22
        1017Lenovo79Oct-22
        1017Lenovo169Nov-22
        1018Apple293Nov-22
        1018Apple190Oct-22
        1018Apple143Oct-22
        1018Apple13Sep-22
        1018Apple125Oct-22
        1019Starbucks235Nov-22
        1019Starbucks217Nov-22
        1019Starbucks86Oct-22
        1019Starbucks10Sep-22
        1019Starbucks83Dec-22
        1020Samsung73Dec-22
        1020Samsung272Dec-22
        1020Samsung115Dec-22
        1020Samsung75Dec-22
        1020Samsung107Oct-22
        1007Lifebuoy0Dec-22
        1007Lifebuoy0Sep-22
        1007Lifebuoy0Oct-22
        1007Lifebuoy0Nov-22
        1007Lifebuoy0Dec-22
        1010McDonalds0Oct-22
        1010McDonalds0Sep-22
        1010McDonalds0Oct-22
        1010McDonalds0Nov-22
        1010McDonalds0Dec-22

         

        Range table

        00No Rev1
        0.001100$ 0 to 1002
        101500$ 101 to 5003
        5011000$ 501 to 10004
        10011500$ 1001 to 15005
        15011000000> $15006

         

        Hope this helps!

  • hi,

     

    Please try this

     

    Rev Range =
    SWITCH (
    SELECTEDVALUE ( 'RangeTable'[Range] ),
    "< $0",
    CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustID], [Rev_Current YTD] < 0 )
    ),
    "$0 to $100",
    CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustID], [Rev_Current YTD] > 0 && [Rev_Current YTD] <= 100 )
    ),
    "$101 to $500",
    CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustID], [Rev_Current YTD] > 100 && [Rev_Current YTD] <= 500 )
    ),
    "$501 to $1000",
    CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustID] , [Rev_Current YTD] > 500 && [Rev_Current YTD] <= 1000 )
    ),
    "$1001 to $1500",
    CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustID], [Rev_Current YTD] > 1000 && [Rev_Current YTD] <= 1500 )
    ),
    "> $1500"
    )

     

     

    If this doesnt work, can you share the calculation used for Rev_current_YTD. that might be causing an issue.

     

    Thanks!

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello alekhved , I tried the formula but DISTINCTCOUNT only accepts one argument. It shows an error if there is more than one input

      • alekhved's avatar
        alekhved
        Resolver I

        hi Anonymous 

         

        My Bad!

        Please try this

         

        Rev Range =
        SWITCH (
        SELECTEDVALUE ( 'RangeTable'[Range] ),
        "< $0",
        CALCULATE (
        DISTINCTCOUNT ( 'Table'[CustID]), [Rev_Current YTD] < 0 ),
        "$0 to $100",
        CALCULATE (
        DISTINCTCOUNT ( 'Table'[CustID]), [Rev_Current YTD] > 0 && [Rev_Current YTD] <= 100 ),
        "$101 to $500",
        CALCULATE (
        DISTINCTCOUNT ( 'Table'[CustID]), [Rev_Current YTD] > 100 && [Rev_Current YTD] <= 500 ),
        "$501 to $1000",
        CALCULATE (
        DISTINCTCOUNT ( 'Table'[CustID]) , [Rev_Current YTD] > 500 && [Rev_Current YTD] <= 1000 ),
        "$1001 to $1500",
        CALCULATE (
        DISTINCTCOUNT ( 'Table'[CustID]), [Rev_Current YTD] > 1000 && [Rev_Current YTD] <= 1500 ),
        "> $1500"
        )

         

        Thanks!