Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
venug
Helper II
Helper II

DAX - Define Store Type ( multiple may be req-if conditions)

Hi Everybody,

 

I want to define store types with my data.

 

oct'18 > 0 sales & oct'19 > 0 sales & same store should repeat in both months = RS

oct'18 > 0 sales & oct'19 < 0 sales & same store should repeat in both months = LS

oct'18 < 0 sales & oct'19 > 0 sales & same store should repeat in both months = ES

 oct'19 > 0 sales  = NS

 

i want to achieve new column using DAX qurie. output is also provided in excel sheet.

 

anybody can help on this,

 

Thanks in advance.

 

Regards

Venu

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @venug ,

 

Please create a calculated column as below.

Column = 
VAR code = 'Table'[Store Code]
VAR oct18 =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2018 )
    )
VAR oct19 =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2019 )
    )
VAR c =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2018 )
    )
RETURN
    IF (
        YEAR ( 'Table'[Date] ) > 2018,
        IF (
            oct18 > 0
                && oct19 > 0,
            "RS",
            IF (
                oct18 > 0
                    && oct19 <= 0,
                "LS",
                IF (
                    c <> BLANK ()
                        && oct18 <= 0
                        && oct19 > 0,
                    "ES",
                    IF ( oct19 > 0 && ISBLANK ( c ), "NS" )
                )
            )
        )
    )

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

4 REPLIES 4
v-frfei-msft
Community Support
Community Support

Hi @venug ,

 

Please create a calculated column as below.

Column = 
VAR code = 'Table'[Store Code]
VAR oct18 =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2018 )
    )
VAR oct19 =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2019 )
    )
VAR c =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2018 )
    )
RETURN
    IF (
        YEAR ( 'Table'[Date] ) > 2018,
        IF (
            oct18 > 0
                && oct19 > 0,
            "RS",
            IF (
                oct18 > 0
                    && oct19 <= 0,
                "LS",
                IF (
                    c <> BLANK ()
                        && oct18 <= 0
                        && oct19 > 0,
                    "ES",
                    IF ( oct19 > 0 && ISBLANK ( c ), "NS" )
                )
            )
        )
    )

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

@v-frfei-msft 

 

Thanks a lot for provide solution. It's really helpful to me.

Regards

Venu.

@v-frfei-msft 

 

I try to define store for 2018 also,

 

The condition is :

 

oct'18 > 0 sales  = RS

oct'18 > 0 sales & oct'19 < 0 sales & same store should repeat in current months = LS

 

i have prepared code for this requirement, but it is executed for only one month either 2018 or 2019.

 

Column =
VAR code = 'Table'[Store Code]
VAR oct18 =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2018 )
)
VAR oct19 =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2019 )
)
VAR c =
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2018 )
)
VAR c1 =
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER ( 'Table', 'Table'[Store Code] = code && YEAR ( 'Table'[Date] ) = 2019 )
)
RETURN
IF (
'Table'[Date].[Year] = 2018,
IF (
oct18 > 0
&& c1 <> BLANK (),
"RS",
IF (
oct18 > 0
&& ISBLANK ( c1 ),
"LS",
IF (
YEAR ( 'Table'[Date] ) > 2018,
IF (
oct18 > 0
&& oct19 > 0,
"RS",
IF (
oct18 > 0
&& oct19 <= 0,
"LS",
IF (
c <> BLANK ()
&& oct18 <= 0
&& oct19 > 0,
"ES",
IF ( oct19 > 0 && ISBLANK ( c ), "NS" )
)
)
)
)
)
)
)

 

venug
Helper II
Helper II

Hi Everybody,

 

Can you  please help on this. Thanks in advance.

 

Regards

Venu

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.