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
venug
Helper II
Helper II

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

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community 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:

b1.png

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.

View solution in original post

2 REPLIES 2
v-alq-msft
Community Support
Community 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:

b1.png

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.

@v-alq-msft Thanks a lot..

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.