Forum Discussion

Jeenz's avatar
Jeenz
Frequent Visitor
4 years ago
Solved

Filter having conditions from multi[ple tables

Problem:

  1. Non - Microsoft  Resellers who do not have Transactions with MS from 2020-07 to 2022-06

 conditions:

 

  • Vendor partner NOT EQUAL TO "Microsoft" (Vendor table)
  • Reseller[Is Test Reseller]="False" (Reseller table)
  • Subscription[Is Trial]="False" 
    (Subscription table)
  • Dates b/w 2020,7,1 to 2022,6,1 (Date column is in Calendar table)

 

 

I need  a DAX function including all these filters from different table . How can I achieve that?

 

 

Qualified =

VAR  C1 = CALCULATETABLE(VALUES(Reseller[Company Name]),

FILTER(Vendor, Vendor[Parent Vendor]<>"Microsoft"|| Vendor[Parent Vendor]<>"Microsoft-Azure"||Vendor[Parent Vendor]<>"Microsoft-Dynamics"|| Vendor[Parent Vendor]<>"Microsoft-Modern"|| Vendor[Parent Vendor]<>"Microsoft-Other"|| Vendor[Parent Vendor]<>"Microsoft-Perpetual"))

VAR C2=CALCULATETABLE(VALUES(Reseller[Company Name]),FILTER(Reseller,Reseller[Is Test Reseller]="False"))

VAR C3=CALCULATETABLE(VALUES(Reseller[Company Name]),FILTER(Subscription,Subscription[Is Trial]="False"))

VAR C4=CALCULATETABLE(VALUES(Reseller[Company Name]),

    'Calendar',

    DATESBETWEEN ( 'Calendar'[Date], DATE(2020,7,1), DATE(2020,6,1) )

)

VAR UnionResult= UNION(C1,C2,C3,C4)

Return COUNTROWS( UnionResult)

 

I wrote something related to that above!

  • Hi Jeenz 

    The UNION function in DAX doesn't remove duplicates like it does with SQL.  Is that the problem?  If so, change this line as follows

    VAR UnionResult = 
    DISTINCT(
        UNION(C1,C2,C3,C4)
    )

     

    For what it's worth, I wonder if you coule simplify your measure immensely with the following

    CALCULATETABLE(
    	VALUES(Reseller[Company Name]),
    	Vendor[Parent Vendor] <> "Microsoft", -- continue this as necessary
    	Reseller[Is Test Reseller] = FALSE(), -- you should have set this as a boolean field, not text
    	Subscription[Is Trial] = FALSE(), -- also boolean
    	('Calendar'[Date] >= DATE(2020, 6, 1) &&
    	'Calendar'[Date] <= DATE(2020, 7, 1))
    )

     

     Hope this helps!

2 Replies

  • littlemojopuppy's avatar
    littlemojopuppy
    Icon for Community Champion rankCommunity Champion

    Hi Jeenz 

    The UNION function in DAX doesn't remove duplicates like it does with SQL.  Is that the problem?  If so, change this line as follows

    VAR UnionResult = 
    DISTINCT(
        UNION(C1,C2,C3,C4)
    )

     

    For what it's worth, I wonder if you coule simplify your measure immensely with the following

    CALCULATETABLE(
    	VALUES(Reseller[Company Name]),
    	Vendor[Parent Vendor] <> "Microsoft", -- continue this as necessary
    	Reseller[Is Test Reseller] = FALSE(), -- you should have set this as a boolean field, not text
    	Subscription[Is Trial] = FALSE(), -- also boolean
    	('Calendar'[Date] >= DATE(2020, 6, 1) &&
    	'Calendar'[Date] <= DATE(2020, 7, 1))
    )

     

     Hope this helps!