Forum Discussion

MandoPavs008's avatar
MandoPavs008
Icon for Helper I rankHelper I
2 years ago
Solved

Compare one category with the rest.

Hello,

I need help with dax for a Clustered column & Clustered Bar visuals to show comparison of one category with rest as others. I would like to create a clustered column visual with X-AXIS as year or mm-yy and y-axis as sum of count and one column as selected category and another column as rest categories. When no category selected then two columns should show ALL categories which will be equal columns of same count. For clustered bar visual, X axis has sum of count and y - axis has to be categories, in that categories ALL should be added as a category as a baseline to show. This visual should change based on year or MM-YY selection. Thank you.

 

CategoryMM-YYcount
A1/1/201815
A2/1/201810
A3/1/201820
A4/1/201821
A5/1/201822
A6/1/201815
A7/1/201816
A8/1/201817
A9/1/201818
A10/1/201814
A11/1/201812
A12/1/201810
B1/1/201815
B2/1/201810
B3/1/201820
B4/1/201821
B5/1/201822
B6/1/201815
B7/1/201816
B8/1/201817
B9/1/201818
B10/1/201814
B11/1/201812
B12/1/201810
C1/1/201810
C2/1/201810
C3/1/201810
C4/1/201810
C5/1/201810
C6/1/201810
C7/1/201810
C8/1/201810
C9/1/201810
C10/1/201810
C11/1/201810
C12/1/201810
D1/1/201815
D2/1/201810
D3/1/201820
D4/1/201821
D5/1/201822
D6/1/201815
D7/1/201816
D8/1/201817
D9/1/201818
D10/1/201814
D11/1/201812
D12/1/201810
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi MandoPavs008 

     

    Just change the ALL measure:

    ALL =
    VAR _slicer =
        VALUES ( 'Table'[Category] )
    VAR _currentmonth =
        MONTH ( MAX ( 'Table'[MM-YY] ) )
    VAR _currentYear =
        YEAR ( MAX ( 'Table'[MM-YY] ) )
    VAR _vtable =
        FILTER (
            ALL ( 'Table' ),
            FIND (
                'Table'[Category],
                CONCATENATEX ( VALUES ( 'Table'[Category] ), [Category] ),
                ,
                BLANK ()
            )
                = BLANK ()
        )
    VAR _All =
        SUMX (
            FILTER (
                _vtable,
                MONTH ( [MM-YY] ) = _currentmonth
                    && YEAR ( [MM-YY] ) = _currentYear
            ),
            [count]
        )
    RETURN
        IF ( ISFILTERED ( 'Table'[Category] ) = FALSE (), SUM ( 'Table'[count] ), _All )
    

    The result is as follow:

     

    Best Regards

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

6 Replies

  • Your sample data is not suitable for your premise.

     

     

    • MandoPavs008's avatar
      MandoPavs008
      Icon for Helper I rankHelper I

      Thank you for your response. The solution didn't work for my requirement. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MandoPavs008 

     

    Please try this:

    Here I create 2 measures:

    ALL =
    VAR _slicer =
        VALUES ( 'Table'[Category] )
    VAR _currentmonth =
        MONTH ( MAX ( 'Table'[MM-YY] ) )
    VAR _currentYear =
        YEAR ( MAX ( 'Table'[MM-YY] ) )
    VAR _vtable =
        FILTER (
            ALL ( 'Table' ),
            FIND (
                'Table'[Category],
                CONCATENATEX ( VALUES ( 'Table'[Category] ), [Category] ),
                ,
                BLANK ()
            )
                = BLANK ()
        )
    RETURN
        SUMX (
            FILTER (
                _vtable,
                MONTH ( [MM-YY] ) = _currentmonth
                    && YEAR ( [MM-YY] ) = _currentYear
            ),
            [count]
        )
    
    Selected =
    VAR _slicer =
        VALUES ( 'Table'[Category] )
    VAR _currentmonth =
        MONTH ( MAX ( 'Table'[MM-YY] ) )
    VAR _currentYear =
        YEAR ( MAX ( 'Table'[MM-YY] ) )
    VAR _vtable =
        FILTER (
            ALL ( 'Table' ),
            FIND (
                'Table'[Category],
                CONCATENATEX ( VALUES ( 'Table'[Category] ), [Category] ),
                ,
                BLANK ()
            )
                <> BLANK ()
        )
    RETURN
        SUMX (
            FILTER (
                _vtable,
                MONTH ( [MM-YY] ) = _currentmonth
                    && YEAR ( [MM-YY] ) = _currentYear
            ),
            [count]
        )
    

    Then add a Clustered column chart:

    and a Clustered bar chart:

    Next add 2 slicer:

    Select the Category and click the Edit interaction in the Format pane:

    And click the button of the Category chart:

     

    The same to MM-YY Slicer and Clustered column chart:

    The result is as follow:

     

    Best Regards

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

    • MandoPavs008's avatar
      MandoPavs008
      Icon for Helper I rankHelper I

      Thank you for the solution. I got the bar chart but the column measure which i created is not working clearly. I would like to create the clustered column visual with Slicer for categories as A, B, C, D. When i select a Category "A' then it should compare with the rest so one column has selected "A" and another column has total count for rest of the category as one column. If no category selected then two columns should show same count as ALL. I want to have one slicer  for category instead of two. Can you please look in to it? 

       

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi MandoPavs008 

         

        Just change the ALL measure:

        ALL =
        VAR _slicer =
            VALUES ( 'Table'[Category] )
        VAR _currentmonth =
            MONTH ( MAX ( 'Table'[MM-YY] ) )
        VAR _currentYear =
            YEAR ( MAX ( 'Table'[MM-YY] ) )
        VAR _vtable =
            FILTER (
                ALL ( 'Table' ),
                FIND (
                    'Table'[Category],
                    CONCATENATEX ( VALUES ( 'Table'[Category] ), [Category] ),
                    ,
                    BLANK ()
                )
                    = BLANK ()
            )
        VAR _All =
            SUMX (
                FILTER (
                    _vtable,
                    MONTH ( [MM-YY] ) = _currentmonth
                        && YEAR ( [MM-YY] ) = _currentYear
                ),
                [count]
            )
        RETURN
            IF ( ISFILTERED ( 'Table'[Category] ) = FALSE (), SUM ( 'Table'[count] ), _All )
        

        The result is as follow:

         

        Best Regards

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