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.
I have a table named (data) and two columns team1 and team2
want to undersand
1. count number of maches played by each team and
2. count of wins by each team
input data
team1 | team2 | winner |
a | c | a |
a | b | b |
b | a | b |
b | c | c |
c | a | a |
c | b | b |
d | a | a |
a | d | d |
Ouput data:
Team | matches | wins |
a | 6 | 3 |
b | 4 | 3 |
c | 4 | 1 |
d | 2 | 1 |
Solved! Go to Solution.
Hi @amitgajkal2007
The first step is to transform the table to vertical to make the analysis easier.
You can do it with the "unpivot" option of PQ
Then you will get the table as in the picture :
From here you can create 2 simple dax measures :
1. For matches :
pbix is attached, you can follow my steps at pq and dax.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Hello @amitgajkal2007
As per your question has stated "Dax Query",
Below is the complete DAX code without doing any manipulation in PQ.
Step : Create a Calculated Table for Supporting purpose. Below is the code.
SupportingTable =
UNION(
SELECTCOLUMNS(
'Table',"Teams",'Table'[team1]
),
SELECTCOLUMNS(
'Table',"Teams",'Table'[team2]
) )
Step : Use the below code for your output in DAX studio or DAX query view in Power BI desktop
EVALUATE
VAR _2 =
SELECTCOLUMNS(
SUMMARIZE(
UNION(
SUMMARIZECOLUMNS( 'Table'[team1] ),
SUMMARIZECOLUMNS( 'Table'[team2]
)
), 'Table'[team1]
), "@Teams",'Table'[team1] )
VAR _3 =
ADDCOLUMNS(
_2,"MatchCount",
CALCULATE( COUNT( SupportingTable[Teams] ), FILTER( SupportingTable, SupportingTable[Teams] = [@Teams] ) ),
"Wins",CALCULATE( COUNT('Table'[winner] ), FILTER( 'Table','Table'[winner] = [@Teams] ) )
)
RETURN
_3
Below is the screenshot
Regards
sanalytics
I am trying to use above (mentioned in DAX query) code in a measure but i am not able to get it.
This is a reference table which i have build...actual tbale has 4 table, like 20 columns and realted with each other.
I am not able to use unpivot option if i use it then it create havoc in other dashboards (the slicer simply doesnt filter).
thank you but if you can let me know how i can use it above query in Dax measure then i will use the analogy on actual data.
Thank you
Hi @amitgajkal2007
The first step is to transform the table to vertical to make the analysis easier.
You can do it with the "unpivot" option of PQ
Then you will get the table as in the picture :
From here you can create 2 simple dax measures :
1. For matches :
pbix is attached, you can follow my steps at pq and dax.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Thats good one....i spent hours to figure it out using DAX. Prbolem with this is that it forms many to many relationship that is difficult to handle
Is there a solution using DAX? (Just Curious)
Hi @amitgajkal2007
Happy to help 🙂 Why many to many,
it is just 1 table..
According to DAX, I see that @sanalytics gave a solution.
Unpivoting creates a havoc on other reports. the slicers simply stop to work and doesnt filter.
hence i was asking for DAX approach. I have 4 tables, 20+ columns and 20k+ rows.
Thanks
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 |
---|---|
60 | |
58 | |
54 | |
36 | |
33 |
User | Count |
---|---|
79 | |
66 | |
45 | |
44 | |
42 |