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
Anonymous
Not applicable

Number of NEW customers each month

Hi PowerBI experts,

I would like to ask you for help. I have a problem with a task. I need to calculate number of NEW customers each month.

 

I have two tables in my data model - 'tb_item_sales' and 'DateTable' (generated based on min and max Posting date).

 

'tb_item_sales':

Orde numberTransaction IDPosting dateBP CodeItemCodeLineTotalBP Project
1000115/26/2020C004832025105.75A
1000115/26/2020C004832026105.75A
1000215/23/2020C004832166557.5A
1000313/29/2020C00483324682.16A
1000413/25/2020C004833247165.48A
1000514/26/2020C004842025248.8A
1000614/23/2020C004842166332.12A
1000711/29/2020C004843246415.44A
1000811/25/2020C004843247498.76A
1000915/26/2020C004802025105.75B
1001015/23/2020C004802166557.5B
1001113/29/2020C00480324682.16B
1001213/25/2020C004803247165.48B
1001314/26/2020C004792025248.8B
1001414/23/2020C004792166332.12B
1001511/29/2020C004793246415.44B
1001611/25/2020C004793247498.76B
1001714/26/2020C0048532481000B
1001815/26/2020C0048632481111B

 

Here is what i have:

 

New Customer = COUNTROWS(FILTER(SUMMARIZE(ALL(tb_item_sales[BP Code]),tb_item_sales[BP Code],"ThisMonthSales",[Net Total Sales],"PreviousSales",[Previous Sales]),[Net Total Sales]>0 &&[PreviousSales]=0 ))

Net Total Sales = CALCULATE(sum(tb_item_sales[LineTotal]),FILTER(tb_item_sales,tb_item_sales[Transaction ID]=1))

MIN date BP code = CALCULATE(MIN(tb_item_sales[Transaction Date]),ALLEXCEPT(tb_item_sales,tb_item_sales[BP Code]))

Previous Sales = CALCULATE (
                SUM( tb_item_sales[LineTotal]),
                FILTER (
                    ALL ( tb_item_sales ),
                    tb_item_sales[Transaction Date]< [MIN date BP code]
                ))

 

My output table should looks like below (red frame):

2020_06_08_19_27_28_Sales_Item_Wise_Tax_Report_Excel.png

New customer means that the previous sales is equal to 0 (before particular each month). That is why C00485 is the new customer in April.

We have a one new customer in project "B"  (in total) and zero new customers in project "A" in April ("BP Project" will be a slicer).

 

Thanks in advance.

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

Hi @Anonymous 

Create a measure

NewCustomersSet = 
    VAR CurrentCustomers = FILTER(VALUES ( 'Table'[BP Code] ),MIN('Table'[Transaction ID])=1)
    VAR OldCustomers =
        FILTER (
            CurrentCustomers,
            CALCULATE (
                MIN ( 'Table'[Posting date] ),
                ALL ( 'date' )
            ) < MIN ( 'date'[Date] )
        )
    RETURN COUNTROWS ( EXCEPT ( CurrentCustomers, OldCustomers ) )

Capture9.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
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-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a measure

NewCustomersSet = 
    VAR CurrentCustomers = FILTER(VALUES ( 'Table'[BP Code] ),MIN('Table'[Transaction ID])=1)
    VAR OldCustomers =
        FILTER (
            CurrentCustomers,
            CALCULATE (
                MIN ( 'Table'[Posting date] ),
                ALL ( 'date' )
            ) < MIN ( 'date'[Date] )
        )
    RETURN COUNTROWS ( EXCEPT ( CurrentCustomers, OldCustomers ) )

Capture9.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you @v-juanli-msft  It works perfectly! the solution is really profesionall. Now i can resign with my temporary solution - calculated column like below:

New customer = 
VAR mycount =
    CALCULATE (
        COUNTROWS (tb_item_sales),
        FILTER (
            ALLEXCEPT ( tb_item_sales, tb_item_sales[BP Code] ),
            tb_item_sales[Data księgowania] < EARLIER ( tb_item_sales[Data księgowania])
        )
    )
RETURN
    IF ( mycount = 0, "Yes" )

 

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.