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
XiananZhaoCSM
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
Employee
Employee

@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

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
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.

Top Solution Authors