Forum Discussion
Using Dax Variables to identifying same value in multiple tables/conditions
I am trying to identify "house ID" that appear in two separate tables and then a third and only count them if the "house ID" appears in all three tables. I am using variables and using Intersect but that is not getting me what I need. Any assistance is helpful
//want to find the values where the value is the same from prior to this new variable
I wrote this before you sent the diagram. See if it works. If not will study your model and have a think!
Test = //Household Codes for clients with active non cash benefits. VAR NonCasha = CALCULATETABLE( VALUES( 'rpt vw_Client_Households'[Household_Code] ), 'rpt vw_Client_Non_Cash_Benefits'[Client_Active] = 1 ) //Household Codes for clients on Low Income Heating Entery Assistance. VAR LIHEAPa = CALCULATETABLE( VALUES( 'rpt vw_Client_Households'[Household_Code] ), 'rpt vw_Client_Programs'[Program] = "Low Income Heating Energy Assistance" ) //Get household codes for clients who either have active non cash benefits or are // in low income energy program. VAR Combined_NonCash_LIHEAP = UNION(NonCasha,LIHEAPa) VAR Unique_NCandLIHEAP = DISTINCT(Combined_NonCash_LIHEAP) // Get household codes from employment table that were found above and are active and who do // have another income source and whose income type is // wages or self-employment. // Use TREATAS to switch the above list from 'rpt vw_Client_Households'[Household_Code] to // 'rpt vw_Client_Household_Employment'[Household_Code] VAR Employ = CALCULATETABLE( VALUES ( 'rpt vw_Client_Household_Employment'[Household_Code] ), 'rpt vw_Client_Household_Employment'[Client_Active] = 1, NOT ( ISBLANK ( 'rpt vw_Client_Household_Employment'[HH_Other_Income_Source] ) ), 'rpt vw_Client_Household_Employment'[Income_Type] IN { "Wages", "Self-employment" } TREATEAS ( Unique_NCandLIHEAP, 'rpt vw_Client_Household_Employment'[Household_Code] ) ) RETURN COUNTROWS ( Employ )
20 Replies
- bcdobbsCommunity Champion
What output do you need? Eg how will you use the measure?
- lchaplenHelper II
Counts of unique values that are in all 4 variables. Example if Houshold A was in all 4 of the variables logic then A would be counted. If houshold B was only in 3 of the 4 variables then I wouldn't want them counted
- bcdobbsCommunity Champion
I think you can make life easier by using your earlier table variables as filters in subsequent. Something along lines of...
VAR Tbl1 =
CALCULATETABLE(
VALUES('rpt vw_Client_Households'[Household_Code]),
Your Logic)
VAR Tbl2 =
CALCULATETABLE(
VALUES('rpt vw_Client_Households'[Household_Code]),
Your Logic,
Tbl1)
VAR Tbl3 =
CALCULATETABLE(
VALUES('rpt vw_Client_Households'[Household_Code]),
Your Logic,
Tbl2)
RETURN
COUNTROWS (Tbl3)
- lchaplenHelper II
Ben
Hi I tried to do as you recommended.. I think it will work.. but I'm getting the error: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
on this:TEST NCOIEmP =VAR HH = CALCULATE('rpt vw_Client_Households','rpt vw_Client_Households'[Household_Code],FILTER('rpt vw_Client_Households','rpt vw_Client_Households'[Client_Active]=1))VAR NonCasha =CALCULATE('rpt vw_Client_Households','rpt vw_Client_Households'[Household_Code],FILTER('rpt vw_Client_Non_Cash_Benefits','rpt vw_Client_Non_Cash_Benefits'[Client_Active] = 1 ))VAR LIHEAPa =CALCULATE('rpt vw_Client_Households','rpt vw_Client_Households'[Household_Code], FILTER('rpt vw_Client_Programs','rpt vw_Client_Programs'[Program] = "Low Income Heating Energy Assistance"))VAR OI =CALCULATE('rpt vw_Client_Households','rpt vw_Client_Households'[Household_Code],FILTER('rpt vw_Client_Household_Employment','rpt vw_Client_Household_Employment'[Client_Active] = 1), FILTER('rpt vw_Client_Household_Employment', NOT(ISBLANK('rpt vw_Client_Household_Employment'[HH_Other_Income_Source]))))VAR Employ =CALCULATE('rpt vw_Client_Households','rpt vw_Client_Households'[Household_Code],FILTER('rpt vw_Client_Household_Employment','rpt vw_Client_Household_Employment'[Client_Active] = 1 ),FILTER('rpt vw_Client_Household_Employment', 'rpt vw_Client_Household_Employment'[Income_Type]= "Wages" || 'rpt vw_Client_Household_Employment'[Income_Type]= "Self-employment"))RETURNCALCULATE (DISTINCT('rpt vw_Client_Households'[Household_Code]),OI,Employ,(NonCasha||LIHEAPa))- bcdobbsCommunity Champion
Hi,
In your original code you were using CALCULATETABLE on VALUES in order to apply a specific filter context and return a single column of values. I was suggesting you could take each table variable in turn and use it as a filter directly in the next.
In the new code you've sent you're only using CALCULATE which expects an expression that returns a scalar. Instead you're passing it a full table.