Forum Discussion

ddpl's avatar
ddpl
Icon for Solution Sage rankSolution Sage
3 years ago
Solved

Compare values from two tables and get count...

Hello,

 

I have two tables,

First one is... Sales,

SaleID_Product Type_Customer_Discount
1ARam15
2BRam16
3BKrishna17
4CKrishna18
5DKrishna19
6ARamesh20
7BRamesh21
8BRamesh22
9BRamesh23
10CKaplesh24
11CKaplesh25
12DKaplesh26

 

and the second one is... Stock,

StockID_Product Type_Discount
1A10
2A11
3A12
4A13
5A14
6B15
7B16
8B17
9B18
10B19
11C20
12C21
13C22
14C23
15C24
16D25
17D26
18D27
19D28
20D29

 

Both tables are connected to [Product Type] column.

 

I want last column in below table, 

Count of Unique [StockID] with one condition that Stock [Discount] must be greater than Sold [Discount] 

 

Customer_Total Sold Quantity_Available Stock_Actual Stock Quantity
Ram2100(A)+3(B) = 3
Krishna3152(B)+5(C)+5(D) = 12
Ramesh4150(A)+ 0(all 3 B types) = 0
Kalpesh3100(all 2 C type) + 3(D) = 3

 

I want the highlighted in Red colour values, extra details are just explaination.

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi ddpl ,

    Please try below steps:

    1. create a measure with below dax formula

    Measure =
    VAR cur_customer =
        SELECTEDVALUE ( Sales[Customer_] )
    VAR tmp1 =
        SELECTCOLUMNS (
            Stock,
            "Stock ID", [StockID_],
            "Product Type", [Product Type_],
            "Count", [Discount]
        )
    VAR tmp2 =
        CROSSJOIN ( Sales, tmp1 )
    VAR tmp3 =
        CALCULATETABLE (
            VALUES ( Stock[StockID_] ),
            FILTER (
                tmp2,
                [Customer_] = cur_customer
                    && [Product Type] = [Product Type_]
                    && [Count] > [Discount]
            )
        )
    VAR _val =
        COUNTROWS ( tmp3 )
    RETURN
        IF ( ISBLANK ( _val ), 0, _val )
    

    2. add a table visual  with field and measure 

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • ddpl's avatar
    ddpl
    3 years ago

    Anonymous ,

     

    Thanks for the answer, it perfectly work on sample data.

     

    but concern is about cross join, as per my data... cross join created around 9 billion rows and the figure did not show untill I sliced any single customer.

     

    Anyway thanks again for the enlightenment.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ddpl ,

    Please try below steps:

    1. create a measure with below dax formula

    Measure =
    VAR cur_customer =
        SELECTEDVALUE ( Sales[Customer_] )
    VAR tmp1 =
        SELECTCOLUMNS (
            Stock,
            "Stock ID", [StockID_],
            "Product Type", [Product Type_],
            "Count", [Discount]
        )
    VAR tmp2 =
        CROSSJOIN ( Sales, tmp1 )
    VAR tmp3 =
        CALCULATETABLE (
            VALUES ( Stock[StockID_] ),
            FILTER (
                tmp2,
                [Customer_] = cur_customer
                    && [Product Type] = [Product Type_]
                    && [Count] > [Discount]
            )
        )
    VAR _val =
        COUNTROWS ( tmp3 )
    RETURN
        IF ( ISBLANK ( _val ), 0, _val )
    

    2. add a table visual  with field and measure 

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • ddpl's avatar
      ddpl
      Icon for Solution Sage rankSolution Sage

      Anonymous ,

       

      Thanks for the answer, it perfectly work on sample data.

       

      but concern is about cross join, as per my data... cross join created around 9 billion rows and the figure did not show untill I sliced any single customer.

       

      Anyway thanks again for the enlightenment.