Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi everyone!
I need to generate a new column in my report using DAX. This new column should contain the sum of occurrences of a value in Column A based on the values in Column B.
Can someone help me?
Table example.
Column A Column B (only unique values)
------------------------------------
Car Jet
Jet Car
Bus Bus
Bus Bike
Car Plane
Car Boat
I would like the output to be:
Column A Column B Column C
----------------------------------------------------------
Car Jet 1
Jet Car 3
Bus Bus 2
Bus Bike 0
Car Plane 0
Car Boat 0
Here is an example in python of what I need to do in DAX.
PS. I can't use python script in power bi.
Solved! Go to Solution.
Hi @TiagoTED
Try this code to add a new column:
Column C =
VAR _B =
FIRSTNONBLANK ( 'Table'[Column B], "" )
VAR _C =
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER ( ALL ( 'Table' ), 'Table'[Column A] = _B )
)
RETURN
IF ( ISBLANK ( _C ), 0, _C )
Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos✌️!!
Hi @TiagoTED
Try this code to add a new column:
Column C =
VAR _B =
FIRSTNONBLANK ( 'Table'[Column B], "" )
VAR _C =
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER ( ALL ( 'Table' ), 'Table'[Column A] = _B )
)
RETURN
IF ( ISBLANK ( _C ), 0, _C )
Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos✌️!!
Thanks so much for the help, the code worked perfectly!
I hope this answer can help others!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
11 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
12 | |
11 | |
11 | |
10 |