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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ddpl
Solution Sage
Solution Sage

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.

 

2 ACCEPTED SOLUTIONS
v-binbinyu-msft
Community Support
Community Support

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 

vbinbinyumsft_0-1677808607119.png

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.

View solution in original post

@v-binbinyu-msft ,

 

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.

View solution in original post

2 REPLIES 2
v-binbinyu-msft
Community Support
Community Support

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 

vbinbinyumsft_0-1677808607119.png

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.

@v-binbinyu-msft ,

 

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.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.