cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
XiananZhaoCSM Frequent Visitor
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.

 

You can download the Power BI file Here

 

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"

 

Thank you for your help.

 

Sherman

2 REPLIES 2
v-haibl-msft Super Contributor
Super Contributor

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 () ),
    "Not Buy",
    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" )
        )
    )
)

Condition column based on sales and date_1.jpg

 

Best Regards,

Herbert

XiananZhaoCSM Frequent Visitor
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

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 301 members 3,020 guests
Please welcome our newest community members: