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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Best approach for calculating counts

Hey All,

Looking for the best/correct approach to add a calculated count column to a table.

I have a clients table which is simple at first sight.

StatusTypeSexCount

 

The count column is a calculated one. It is also not complicated.

CALCULATE(DISTINCTCOUNT(CLIENTS[ID]),
FILTER(....),
FILTER(....),
FILTER(....),
FILTER(....))

Each row count differs from one another by sex ,age range, and status. Sex and status are availble in the table, while age is from a different table.

 

I easily created a few measures, with the other table, which represents each record in the table.

 

How do I connect it all together?

Cheers!
A

5 REPLIES 5
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

Based on having created relationships among the tables. you can try to create measure like DAX below, multiple FILTER function can be used in a formula, maybe the filter condition about [age] part need to be changed by the actual request.

 

Count = CALCULATE(DISTINCTCOUNT(CLIENTS[ID]),FILTER(ALLSELECTED(CLIENTS),CLIENTS[Status]=MAX(CLIENTS[Status])&&CLIENTS[Sex]=MAX(CLIENTS[Sex])),FILTER(ALLSELECTED(Other_table),Other_table[age]=MAX(Other_table[age])))

 

If I misunderstand it, could you please share your sample data or desired output screenshots for further analysis, you can also upload sample pbix to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Hi @v-xicai 

Thanks for the answer.

the issue is that the sex/status/age changes for every record.

The table I have is a standalone and cannot be related to any other table. i.e. no foreign key to other table(s).

 

The current table I have is (For example)

_STATUSCHECK_TYPESEXELIGIBLE_CLIENTS (Current)CLIENT_GRP_NOELIGIBLE_CLIENTS (Expected)
Current Over 15F249911224
Past Over 15F14325562
Transient Over 15F159277
Current Over 15M270911416
Past Over 15M1511573
Transient Over 15M1402650
Current Over 55F24991 
Past Over 55F14325 
Transient Over 55F1592 
Current Over 55M27091 
Past Over 55M15115 
Transient Over 55M1402 
Current Over 75 31 
Past Over 75 65 
Transient Over 75 42 
Current Over 75F31751 
Past Over 75F29055 
Transient Over 75F5632 
Current Over 75M33181 
Past Over 75M28765 
Transient Over 75M3542 

 

The current ELIGIBLE_CLIENTS number is showing a wrong number, as it is not filtered correctly.

I have a measure outside the table that shows the correct one. For instance

Eligible_Clients = CALCULATE(DISTINCTCOUNT(CLIENTS[ID]),
FILTER(...),
FILTER(...),
FILTER(...),
FILTER(...)
)

Can I use these measures in a table? If yes, how?
Or, can I apply filters on specific values in a table?

Thanks
A

Hi @Anonymous ,

 

Confused about what is your desired output now, for example the relationship between the main table and other table.

 

2.png

 

 

 

 

 

 

 

 

If you need to create relationship between two tables which have no foreign key, you can create intermediate table like DAX below, then create relationships between this intermediate table and other two tables.

 

intermediate table = CROSSJOIN(DISTINCT(SELECTCOLUMNS(Table1,"name1",Table1[field1])),DISTINCT(SELECTCOLUMNS(Table2,"name2",Table2[field2])))

 

Best Regards,

Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Anonymous
Not applicable

@v-xicai 

TYPO.

That shold be clients.

The question is really, how to use/relate a measure in a table.

ThankS

A

@v-xicai , I just wanted to leave you a note to say that your comment about the DISTINCTCOUNT calculation *really* helped me overcome a hurdle I had regarding counts across related tables in a (sort of) star schema. Thanks so much for contributing this.

 

Will this calculation travel across tables? I.e., if I have a table of distinct values between two tables, do I need to specify USERELATIONSHIP, or can I just name the table and column regardless of how "far away" it is from the table where I'm generating the count? I hope that makes some sense....

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.