March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello,
I am kind of stuck in something that I feel is easy to solve and I need your help (once again).
I got two tables connected with a relationship 1 to many like the below:
Table 1
ID | Reason ID |
1 | ##1 |
2 | ##2 |
3 | ##2 |
4 | ##3 |
Table 2
Reason ID | Reason Name |
##1 | Name 1 |
##2 | Name 2 |
##3 | Name 3 |
##4 | Name 4 |
[Table 1] *--1 [Table 2] (both way direction)
I want to create cards (or card by placing all the calculations inside the measure and concatenate the results) in which I will show with a calculation the following:
Top Reason by distinct count of ID --> Based on tables above the result will be: "Name 2"
Distinct Count of ID which correspond to the Top Reason --> Based on tables above the result will be: 2
Proportion of the Distinct Count of ID which correspond to the Top Reason in comparison with the total distinct count of ID's in the first table --> Based on tables above the result will be: 2/4 (total Population) = 50%
I hope that makes sense, I tried to use the TOPN function in combination with the MAX but didn't make it.
Any suggestions?
Thanks
Solved! Go to Solution.
Managed at least to find how to syntax the formula based on the answer @amitchandak gave me.
Top Reason Card =
Calculate all the available ID's in table1
Var NumberofID =
DISTINCTCOUNT(table1[ID])
// return the reason with the biggest count of ID's (first ask)
Var TopReason =
CALCULATE(
MAX(table2[Reason Name]), topn(1, ALLSELECTED(table2[Reason Name]), calculate(COUNT(table1[ID])), DESC), VALUES(table2[Reason Name])
)
// calculate the count of ID's under the reason with the biggest count (ask 2)
Var CalcReference = CALCULATE(DISTINCTCOUNT(table1[ID]), table2[Reason Name] = TopReason)
// calculate the percentage in comparison to the total population (ask 3)
Var PercReference = FORMAT(CalcReference/NumberofID,"##%")
Return
Var TopReason & " - " & CalcReference & " / " & CalcReference
// that will return
Name 2 - 2 / 50%
Managed at least to find how to syntax the formula based on the answer @amitchandak gave me.
Top Reason Card =
Calculate all the available ID's in table1
Var NumberofID =
DISTINCTCOUNT(table1[ID])
// return the reason with the biggest count of ID's (first ask)
Var TopReason =
CALCULATE(
MAX(table2[Reason Name]), topn(1, ALLSELECTED(table2[Reason Name]), calculate(COUNT(table1[ID])), DESC), VALUES(table2[Reason Name])
)
// calculate the count of ID's under the reason with the biggest count (ask 2)
Var CalcReference = CALCULATE(DISTINCTCOUNT(table1[ID]), table2[Reason Name] = TopReason)
// calculate the percentage in comparison to the total population (ask 3)
Var PercReference = FORMAT(CalcReference/NumberofID,"##%")
Return
Var TopReason & " - " & CalcReference & " / " & CalcReference
// that will return
Name 2 - 2 / 50%
@Kostas , Try a measure like
CALCULATE(concatenatex(Table, Table[ID]) ,TOPN(1,allselected(Table2[Reason Name]),calculate(Count(Table1[ID])),DESC),VALUES(Table2[Reason Name]))
Hello @amitchandak
It seems that the measure returns a concatenation of all the ID's from the first table that refer to the reason with most ID's assigned to it.
I need the card to return the "Reason" that has the biggest population in terms of count of ID from the table 1 (as shown above the Reason Name 2 has 2 ID's assigned to it compared with the other reasons that have only 1.
Also, another measure that will return to me the count of ID's that are assigned to the reason that has the most (as mentioned above the number will be 2).
I hope that helps
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
87 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |