Forum Discussion
Using Dax Variables to identifying same value in multiple tables/conditions
- 4 years ago
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 )
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 )
Ben
Thanks this isn't quite right but it certainly helps me figure out how to do it! Thanks so much. I will mark as accept. Thanks again!
- bcdobbs4 years agoCommunity Champion
Glad it's got you nearer! If you get stuck again let me know; always happy to jump on a call or something.
Looking at your model you're probably making life difficult for yourself as it's still very much in the form of a relational database. Using power query or sql to shape it into a star schema is likely to make your dax much easier. (Have a look at SQL BI Introduction to data modelling for Power BI)
- lchaplen4 years agoHelper II
Ben
Thanks I was an advance Report writer in Crystal now Biz Objects so on the learning curve with Power BI. The # don't seem right over inflated.. but will help 🙂 Thanks again
- bcdobbs4 years agoCommunity Champion
Is the logic in the first two variables that get union'd together correct. It's effectively doing an "or" wondered if you really wanted "and".
- lchaplen4 years agoHelper II
HI the first part is an "OR' which is correct. Then the rest should be comparing the first group to see the Household also has the next two conditions other income and employement income. If the Household has all three then it should be counted distinctly.