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

Count Data from Two Columns

Hello all,

I've got a dataset that looks like the below:

IDProg1Prog2
123SPAN 
213ACCTSPAN
343FINA 
593BSADACCT
994ACCT

 

 

What I'd like to do is somehow count each instance of a Prog (regardless of Prog1 or Prog2) in a single visual. In other words, I'd like a column chart that would show SPAN as having 2 and ACCT as having 3 since they each appear in both Prog1 and Prog2 for two individuals. Or to put another way, one ID can be counted in multiple Prog counts based on the values in Prog1 and Prog2. Is there a way to combine counts from two columns in a single visual?

1 ACCEPTED SOLUTION
Sergii24
Super User
Super User

Hi @mljones, adding to what Greg has already suggested to you, you might want to create a separate table that contains unique values using this code:

 

Distinct Progr = 
    DISTINCT(
        UNION(
            DISTINCT( 'Table'[Prog1] ), 
            DISTINCT( 'Table'[Prog2] ) 
        )
    )

 


Now, we can use a single column from this new table (by default Prog1, but you can rename it with double-click) to show the distinct values of Prog1 and Prog2 together:

Sergii24_0-1713801679638.png

Now it's time for counting:

 

Count Progr = 
VAR _CurrentlySelectedProgr = SELECTEDVALUE( 'Distinct Progr'[Prog] )
VAR _CountProgr1 = 
    COUNTROWS(
        FILTER(
            'Table',
            'Table'[Prog1] = _CurrentlySelectedProgr
        )
    )

VAR _CountProgr2 = 
    COUNTROWS(
        FILTER(
            'Table',
            'Table'[Prog2] = _CurrentlySelectedProgr
        )
    )
    
RETURN _CountProgr1 + _CountProgr2

 

 

with the following output:

Sergii24_1-1713801742608.png

To conclude:

  • fristly, you need a list of unique values listed within the same columns based on what you want to make a calculation (can be only column, calculated column or a column of calculated table but not measure)
  • Depending on your semantic model, write a measure that will use existing relationships/lookup or filter (as in my example) to count what you want for each column separately
  • sum single results

Good luck! 🙂

View solution in original post

4 REPLIES 4
Sergii24
Super User
Super User

Hi @mljones, adding to what Greg has already suggested to you, you might want to create a separate table that contains unique values using this code:

 

Distinct Progr = 
    DISTINCT(
        UNION(
            DISTINCT( 'Table'[Prog1] ), 
            DISTINCT( 'Table'[Prog2] ) 
        )
    )

 


Now, we can use a single column from this new table (by default Prog1, but you can rename it with double-click) to show the distinct values of Prog1 and Prog2 together:

Sergii24_0-1713801679638.png

Now it's time for counting:

 

Count Progr = 
VAR _CurrentlySelectedProgr = SELECTEDVALUE( 'Distinct Progr'[Prog] )
VAR _CountProgr1 = 
    COUNTROWS(
        FILTER(
            'Table',
            'Table'[Prog1] = _CurrentlySelectedProgr
        )
    )

VAR _CountProgr2 = 
    COUNTROWS(
        FILTER(
            'Table',
            'Table'[Prog2] = _CurrentlySelectedProgr
        )
    )
    
RETURN _CountProgr1 + _CountProgr2

 

 

with the following output:

Sergii24_1-1713801742608.png

To conclude:

  • fristly, you need a list of unique values listed within the same columns based on what you want to make a calculation (can be only column, calculated column or a column of calculated table but not measure)
  • Depending on your semantic model, write a measure that will use existing relationships/lookup or filter (as in my example) to count what you want for each column separately
  • sum single results

Good luck! 🙂

Thank you!

Greg_Deckler
Community Champion
Community Champion

@mljones Typically you would unpivot those columns but you can use MC Aggregations: Multi-Column Aggregations (MC Aggregations) - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you!

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.