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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
JoshEnglish
Helper I
Helper I

Count occurrences of Yes values

I have merged two tables, a list of accounts against a  list of accounts in groups so I now have:

 

Account Group

------- -----

1       null

2       A

3       A

4       B

 

I am trying to create columns in the query that count the number of times each group appears in the merged table AND count the number of times the group appears in the original table of groups.

 

If the original Group table is:

Account Group

------- -----

2       A

3       A

4       B

5       B

 

I need columns:

Account Group Here There

------- ----- ---- -----

1       null  0    0

2       A     2    2

3       A     2    2

4       B     1    2

 

Eventually I need to have a single list of all Accounts where Group is null, and the Group value if Here = There, (i.e. 1, A, 4) but that's a different issue altogether.

 

Any suggestions?

1 ACCEPTED SOLUTION

@JoshEnglish

 

Try these Columns in MergedTable

 

There =
CALCULATE (
    COUNTROWS ( OriginalTable ),
    FILTER ( OriginalTable, OriginalTable[Group] = MergedTable[Group] )
)

 

Here =
CALCULATE (
    COUNTROWS ( MergedTable ),
    ALLEXCEPT ( MergedTable, MergedTable[Group] )
)

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

 

I am confused.  What are your inputs and what output do you want?  How did you get the numbers in the Here and There columns?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

The numbers in the "Here" and "There"  columns are the columns I am trying to fill out with Power BI.

 

They are the equivalent of Excel table functions =COUNTIF([GID],[@GID]) and =COUNTIF(Table2[Group ST ID],[@GID])

@JoshEnglish

 

Try these Columns in MergedTable

 

There =
CALCULATE (
    COUNTROWS ( OriginalTable ),
    FILTER ( OriginalTable, OriginalTable[Group] = MergedTable[Group] )
)

 

Here =
CALCULATE (
    COUNTROWS ( MergedTable ),
    ALLEXCEPT ( MergedTable, MergedTable[Group] )
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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