cancel
Showing results for
Did you mean:
Frequent Visitor

## Condition column based on sales and date

Hi experts,

I just start shifting gears from Tableau to Power BI. I came across a problem which I need to add a condition column for every customer based on their sales by month.

Here's the conditions:

(current month is July)

1. If the customer sales of current month is zero or null, then the condition shows "Not Buy"

2. If the customer sales of current month is less than previous month and is also less than the month before previous month, then "Down 2 months" (less than each of the previous month sales, not sum of the previous month sales)

3. If the customer sales of current month is less than previous month sales and is greater than the sales of the month before previous month, then "Down 1 month"

4. If the customer sales of current month is greater than previous month sales, then "Good"

Sherman

2 REPLIES 2
Microsoft

## Re: Condition column based on sales and date

@XiananZhaoCSM

I think we can create three measures for sales of current month, previous month and month before previous month, then create another state measure and put these four measures into one Table chart as below.

I’ve also uploaded the Power Bi file here.

`CurrentMonth = TOTALMTD ( SUM ( Query1[GrossSales] ), DimDate[Date] )`
```PreMonth =
CALCULATE (
SUM ( Query1[GrossSales] ),
DATESMTD ( DATEADD ( DimDate[Date], -1, MONTH ) )
)```
```Month_Before_PreMonth =
CALCULATE (
SUM ( Query1[GrossSales] ),
DATESMTD ( DATEADD ( DimDate[Date], -2, MONTH ) )
)```
```State =
IF (
OR ( [CurrentMonth] = 0, [CurrentMonth] = BLANK () ),
IF (
AND ( [CurrentMonth] < [PreMonth], [CurrentMonth] < [Month_Before_PreMonth] ),
"Down 2 months",
IF (
AND ( [CurrentMonth] < [PreMonth], [CurrentMonth] > [Month_Before_PreMonth] ),
"Down 1 month",
IF ( [CurrentMonth] > [PreMonth], "Good" )
)
)
)```

Best Regards,

Herbert

Frequent Visitor

## Re: Condition column based on sales and date

Thanks for the help, Herbert. It works very well. However, since "State" field is a measure, I could not add it into the page level filters or report level filter. If I create a new column using the "State", I get a "operation cancelled because not enough memory error". (64bit, 16G). What I would like to do is to filter the customers by the "State" field. I will look for a work-around. But thanks again for the great solution.

Sherman

Announcements

#### Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

#### Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

#### Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!