Forum Discussion

venug's avatar
venug
Icon for Helper II rankHelper II
6 years ago
Solved

DAX - Create measure to count Store type

Hi Everyone,

 

Based on store type I need the count of unique outlets at month level ( this was done as it is a direct statement). However they want to implement having multiple months selection. While we select multiple month my categorical column store type will change based on  each month data. To overcome this problem planning to implement below logic, where I need your expertise.

 

 

  1. Filter the data what is required( multiple month) – Table1
  2. Remove the month column and come up with the unique store type based on below logic – Table2
  3. When the store have same in both months the condition like below. - Table2
    1. If store type is “New” in Jan and store type is “Retain” in Feb – the store should treat as “Retain”
    2. If store type is “New” in Jan and store type is “Lapsed” in Feb – the store should treat as “Lapsed”
    3. If store type is “Retained” in Jan and store type is “Retain” in Feb – the store should treat as “Retain”
  4. Then count unique stores in each type as mentioned in the final output. – Table3

 

Table 1:

 

Store

Month

Store type

A

Jan

New

B

Jan

retain

C

Jan

retain

D

Jan

new

E

Jan

new

F

Jan

retain

G

Jan

lapsed

H

Jan

lapsed

A

Feb

retain

B

Feb

lapsed

C

Feb

retain

D

Feb

retain

L

Feb

new

M

Feb

retain

N

Feb

lapsed

T

Feb

retain

 

Output format (Table 2: )

 

E

new

F

retain

G

lapsed

H

lapsed

L

new

M

retain

N

lapsed

T

retain

A

retain

B

lapsed

C

retain

D

retain

 

 

Final Output (Table 3: )

 

Store Type

Count

lapsed

4

new

2

retain

6

Grand Total

12

 

Thanks in advance

 

Regards

Venu

  • Hi, venug 

     

    Based on your description, you can create the Table 2 and Table 3 as follows.

    Table 2 =

    SUMMARIZE (

        'Table 1',

        'Table 1'[Store],

        "Store type",

        VAR j =

            CALCULATE (

                MAX ( 'Table 1'[Store type] ),

                FILTER ( 'Table 1', 'Table 1'[Month] = "Jan" )

            )

        VAR k =

            CALCULATE (

                MAX ( 'Table 1'[Store type] ),

                FILTER ( 'Table 1', 'Table 1'[Month] = "Feb" )

            )

        RETURN

            IF (

                j = "new"

                    && k = "retain",

                "Retain",

                IF (

                    j = "new"

                        && k = "laspsed",

                    "Lapsed",

                    IF (

                        j = "retain"

                            && k = "retain",

                        "Retain",

                        IF ( k = "" || ISBLANK ( k ), j, k )

                    )

                )

            )

    )

     

    Table 3 = SUMMARIZE(

        'Table 2',

        'Table 2'[Store type],

        "Count",

        COUNT('Table 2'[Store type])

                          

    )

     

    Result:

    Table 2:

    Table 3:

    Best Regards,

    Allan

     

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

2 Replies

  • v-alq-msft's avatar
    v-alq-msft
    Icon for Community Support rankCommunity Support

    Hi, venug 

     

    Based on your description, you can create the Table 2 and Table 3 as follows.

    Table 2 =

    SUMMARIZE (

        'Table 1',

        'Table 1'[Store],

        "Store type",

        VAR j =

            CALCULATE (

                MAX ( 'Table 1'[Store type] ),

                FILTER ( 'Table 1', 'Table 1'[Month] = "Jan" )

            )

        VAR k =

            CALCULATE (

                MAX ( 'Table 1'[Store type] ),

                FILTER ( 'Table 1', 'Table 1'[Month] = "Feb" )

            )

        RETURN

            IF (

                j = "new"

                    && k = "retain",

                "Retain",

                IF (

                    j = "new"

                        && k = "laspsed",

                    "Lapsed",

                    IF (

                        j = "retain"

                            && k = "retain",

                        "Retain",

                        IF ( k = "" || ISBLANK ( k ), j, k )

                    )

                )

            )

    )

     

    Table 3 = SUMMARIZE(

        'Table 2',

        'Table 2'[Store type],

        "Count",

        COUNT('Table 2'[Store type])

                          

    )

     

    Result:

    Table 2:

    Table 3:

    Best Regards,

    Allan

     

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