Forum Discussion

mbbzoh's avatar
mbbzoh
Frequent Visitor
1 year ago
Solved

Orders with one product

Hi, I'm beginner in Power Bi and Dax so i think its very simple case, but it's struggle me for couple days.

 

I have table orders which looks like that (of course there are a lot of others columns, but i think not important for this case)

product idorder numerquantity of sales
111
121
222
3310


For each product I want to calculate two measures:
- (A) all orders with that product 
- (B) orders where is only one id product

 

So in results I would like to get that table:

id product(A) numer of orders with product(B) number of orders only with that product
121
210
311

 

  • You can create a couple of measures like

    Num orders only that product =
    VAR OrdersAndNumProducts =
        ADDCOLUMNS (
            VALUES ( 'Orders'[Order num] ),
            "@num products",
                CALCULATE (
                    DISTINCTCOUNT ( 'Orders'[Product ID] ),
                    ALLEXCEPT ( 'Orders', 'Orders'[Order num] )
                )
        )
    VAR Result =
        COUNTROWS ( FILTER ( OrdersAndNumProducts, [@num products] = 1 ) )
    RETURN
        Result
    
    Num orders = COUNTROWS( 'Orders' )

2 Replies

  • You can create a couple of measures like

    Num orders only that product =
    VAR OrdersAndNumProducts =
        ADDCOLUMNS (
            VALUES ( 'Orders'[Order num] ),
            "@num products",
                CALCULATE (
                    DISTINCTCOUNT ( 'Orders'[Product ID] ),
                    ALLEXCEPT ( 'Orders', 'Orders'[Order num] )
                )
        )
    VAR Result =
        COUNTROWS ( FILTER ( OrdersAndNumProducts, [@num products] = 1 ) )
    RETURN
        Result
    
    Num orders = COUNTROWS( 'Orders' )
  • mbbzoh's avatar
    mbbzoh
    Frequent Visitor

    It works, thank You 🙂