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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply

Identify how many uniqie items are sent per order

Hi Power BI fam,

I need your help! 
I need to identify the total number of unique items sent by the customer every order.  

Screenshot 2022-05-30 101450.png

Screenshot 2022-05-30 101500.png

Screenshot 2022-05-30 102351.png


my orders and customer table have a many-to-one relationship through the customer code.
The end result should tell me how many unique items the customer sends every time they send an order. This is identified through the item code we record and reflects on the orders table. 

ANy help is much appreciated

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

I interpret you requirement to be 'number of items in an order which the customer has not bought in a previous order':

number of new products =
VAR _currentDate =
    CALCULATE ( SELECTEDVALUE ( 'Table'[order date] ) )
VAR _currentCustomer =
    CALCULATE ( SELECTEDVALUE ( 'Table'[customer] ) )
VAR _prevProd =
    CALCULATETABLE (
        VALUES ( 'Table'[productID] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[order date] < _currentDate
                && 'Table'[customer] = _currentCustomer
        )
    )
RETURN
    COUNTROWS (
        CALCULATETABLE (
            VALUES ( 'Table'[productID] ),
            FILTER (
                'Table',
                'Table'[customer] = _currentCustomer
                    && 'Table'[order date] = _currentDate
                    && NOT 'Table'[productID] IN _prevProd
            )
        )
    )

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

 

How to Get Your Question Answered Quickly

View solution in original post

1 REPLY 1
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

I interpret you requirement to be 'number of items in an order which the customer has not bought in a previous order':

number of new products =
VAR _currentDate =
    CALCULATE ( SELECTEDVALUE ( 'Table'[order date] ) )
VAR _currentCustomer =
    CALCULATE ( SELECTEDVALUE ( 'Table'[customer] ) )
VAR _prevProd =
    CALCULATETABLE (
        VALUES ( 'Table'[productID] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[order date] < _currentDate
                && 'Table'[customer] = _currentCustomer
        )
    )
RETURN
    COUNTROWS (
        CALCULATETABLE (
            VALUES ( 'Table'[productID] ),
            FILTER (
                'Table',
                'Table'[customer] = _currentCustomer
                    && 'Table'[order date] = _currentDate
                    && NOT 'Table'[productID] IN _prevProd
            )
        )
    )

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

 

How to Get Your Question Answered Quickly

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.