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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
lchaplen
Helper II
Helper II

Calculating unique count across two tables values each with conditions.

I have two tables Programs and Benefits.  There are people I need to count uniquely based on conditions in each table

Programs:   person is active = 1 and Program = XYZ and startdate = MM/DD/YYY

Benefits:  person is active = 1 

A person may be in either or both tables and I need to get a unique count of total people from both tables with the above conditions. 

 

I don't want to count only the people in both tables. I need to count uniquely all people.  I could do this in SQL but haven't been able to crack it in Power BI. 

 

1 ACCEPTED SOLUTION

HI so I cracked it.. one thing to mention in Variables you can't go off another variable.

TEST HH_Non-Cash_Benefit_w_LIHEAP =
VAR NonCasha =
CALCULATETABLE(VALUES('rpt vw_Client_Households'[Household_Code]),FILTER('rpt vw_Client_Non_Cash_Benefits','rpt vw_Client_Non_Cash_Benefits'[Client_Active] = 1 ))
VAR LIHEAPa =
CALCULATETABLE(VALUES('rpt vw_Client_Households'[Household_Code]),'rpt vw_Client_Programs'[Program] = "Low Income Heating Assistance")
VAR Combined_NonCash_LIHEAP = UNION(NonCasha,LIHEAPa)
VAR Unique_NCandLIHEAP = DISTINCT(Combined_NonCash_LIHEAP)
RETURN
Countrows(Unique_NCandLIHEAP)

View solution in original post

3 REPLIES 3
speedramps
Super User
Super User

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  I prefer to teach members on this forum techniques rather give full solutions and do their job. You can then adapt the technique for your solution, learn some DAX skills for next time and soon become a Power BI Super User like me. 😀


Click here to down load an example 

The Program table with people and colours (red, green).
The Benefits table with people and colours (small, medium, large).
The answer has the number of red or small people.

You should be able to easily learn the technique and adapt it to your solution from this example 

 

Red or Small People =
VAR Red_People = CALCULATETABLE(VALUES(Program[Person]),Program[Colour] = "Red")
VAR Small_People = CALCULATETABLE(VALUES(Benefits[Person]),Benefits[Size] = "Small")
VAR Combined_Red_Small_People = UNION(Red_People,Small_People)
VAR Unique_Red_Small_People = DISTINCT(Combined_Red_Small_People)
RETURN
COUNTROWS(Unique_Red_Small_People)
 

Thanks for reaching out for help.

I put in a lot of effort to help you, now please quickly help me by giving kudos.

Remeber we are unpaid volunteers and here to coach you with Power BI and DAX skills and ttechniques, not do the users job for them !

So plaase click the thumbs up and accept as solution button. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

Well it is getting me closer.. this is my formula.. Note the Person code is derived from a 3rd table. I'm getting the error:  "A function 'PLACEHOLDER' has been used in a TRUE/FALSE expression that is used as a table filter expresssion.  This is not allowed" 

 

TEST HH_Non-Cash_Benefit_w_LIHEAP =
VAR NonCash =
CALCULATETABLE(VALUES('rpt vw_Client_Households'[Household_Code]),not(isblank('rpt vw_Client_Household_Employment'[HH Non_Cash])))
VAR LIHEAP =
CALCULATETABLE(VALUES('rpt vw_Client_Households'[Household_Code]),'rpt vw_Client_Programs'[Program] = "Low Income Heating Assistance")
VAR Combined_NonCash_LIHEAP = UNION(NonCash,LIHEAP)
VAR Unique_NCandLIHEAP = DISTINCT(Combined_NonCash_LIHEAP)
RETURN
COUNTROWS(Unique_NCandLIHEAP)

HI so I cracked it.. one thing to mention in Variables you can't go off another variable.

TEST HH_Non-Cash_Benefit_w_LIHEAP =
VAR NonCasha =
CALCULATETABLE(VALUES('rpt vw_Client_Households'[Household_Code]),FILTER('rpt vw_Client_Non_Cash_Benefits','rpt vw_Client_Non_Cash_Benefits'[Client_Active] = 1 ))
VAR LIHEAPa =
CALCULATETABLE(VALUES('rpt vw_Client_Households'[Household_Code]),'rpt vw_Client_Programs'[Program] = "Low Income Heating Assistance")
VAR Combined_NonCash_LIHEAP = UNION(NonCasha,LIHEAPa)
VAR Unique_NCandLIHEAP = DISTINCT(Combined_NonCash_LIHEAP)
RETURN
Countrows(Unique_NCandLIHEAP)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.