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
datastrategy
Frequent Visitor

Counting Events That Happen in Two Tables for Same Data Table

I have patients that were created in a surgery center and accounts that were created in a pharmacy nearby.  Want to know in a given month how many came through from the VW_Patients to the "accounts" (Pharmacy).  They are matched by the "chart number" to "Alternate Account Number".  I keep getting results that total each for a given month, but I want to know only those that matched with the VW_Patients in that month.  

 

Basically two columns with counting patients.  One ("Chart Number") has slightly more than "accounts" because some don't go to the pharmacy.  Want to then calculate the % that go to Pharmacy (accounts) for each month.

 

been looking all day and decided to post.  thanks!

 

 

Annotation 2019-07-17 200417.jpg

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @datastrategy ,

It seems like you want to calculate between two tables. I'd like to suggest you break cleandr table relationships and use formula to manually calculate correspond table count and do compare with them.

Measure =
VAR selected =
    VALUES ( Date[Date] )
VAR _account =
    CALCULATETABLE (
        VALUES ( Account[Alternate Account Number] ),
        FILTER ( ALLSELECTED ( Account ), [Date] IN selected )
    )
VAR _patient =
    CALCULATETABLE (
        VALUES ( VW_Patients[chart number] ),
        FILTER ( ALLSELECTED ( VW_Patients ), [Date] IN selected )
    )
RETURN
    DIVIDE (
        COUNTROWS ( INTERSECT ( _patient, _account ) ),
        COUNTROWS ( _account )
    )

Notice: create a table visual based on date dimension table year, month fields and above measure.

If above not help, can you please share some sample data for test, it is hard to coding formula without any sample data.(do mask on sensitive data)

How to Get Your Question Answered Quickly

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @datastrategy ,

It seems like you want to calculate between two tables. I'd like to suggest you break cleandr table relationships and use formula to manually calculate correspond table count and do compare with them.

Measure =
VAR selected =
    VALUES ( Date[Date] )
VAR _account =
    CALCULATETABLE (
        VALUES ( Account[Alternate Account Number] ),
        FILTER ( ALLSELECTED ( Account ), [Date] IN selected )
    )
VAR _patient =
    CALCULATETABLE (
        VALUES ( VW_Patients[chart number] ),
        FILTER ( ALLSELECTED ( VW_Patients ), [Date] IN selected )
    )
RETURN
    DIVIDE (
        COUNTROWS ( INTERSECT ( _patient, _account ) ),
        COUNTROWS ( _account )
    )

Notice: create a table visual based on date dimension table year, month fields and above measure.

If above not help, can you please share some sample data for test, it is hard to coding formula without any sample data.(do mask on sensitive data)

How to Get Your Question Answered Quickly

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.