Forum Discussion
Count based on disticnt value in another column
Hi Wondering if anyone could help,
I'm trying to do a total cost count for accommodation, but only want to count the value once based on the Family ID (distinct count)
If anyone could help I would really appreciate it
Thanks
Kate_McCulloch , Try using a measure for this
DAX
TotalCostByFamilyID =
SUMX(
SUMMARIZE(
YourTableName,
YourTableName[Family_ID],
"DistinctCost",
MAX(YourTableName[Total Cost Accommodation])
),
[DistinctCost]
)
5 Replies
- bhanu_gautam
Super User
Kate_McCulloch , Try using a measure for this
DAX
TotalCostByFamilyID =
SUMX(
SUMMARIZE(
YourTableName,
YourTableName[Family_ID],
"DistinctCost",
MAX(YourTableName[Total Cost Accommodation])
),
[DistinctCost]
) - alish_b
Super User
Hello Kate_McCulloch ,
I could not totally grasp the question and a snapshot of the expected solution would have helped. I am assuming you are looking for the following format as the end result:
Family_Id Total Cost Accomodation 4128415 1130 4128470 4075 4128484 5283 4128739 525 4129596 1792.27 If the same value repeats for a particular Family_Id in the table, you could simply opt for an min/max/average at Family_Id level either using a measure as following or just dragging-and-dropping and then changing the aggregation style to Min/Max/Average.
Unique Cost Accomodation = MIN(Table[Total Cost Accomodation])
If there is more to the problem, please add some more context and share the end result you are expecting. - rohit1991
Super User
Hi Kate_McCulloch ,
If you want to calculate the total accommodation cost, but count each Family ID only once (even if they appear multiple times in your data), you need a DAX measure that sums the cost just once per unique Family ID. The best way to do this in Power BI is to first summarize your table so that you get the maximum (or minimum, or averageāwhichever is appropriate for your business logic) accommodation cost per Family ID.Then, you sum up those distinct costs across all Family IDs. This ensures that even if a Family ID appears more than once in your table, its accommodation cost is only counted once in the total. The following DAX measure achieves this by summarizing your data by Family ID and then summing up the distinct costs:
TotalCostByFamilyID = SUMX( SUMMARIZE( YourTableName, YourTableName[Family_ID], "DistinctCost", MAX(YourTableName[Total Cost Accommodation]) ), [DistinctCost] ) - Kate_McCullochRegular Visitor
worked exactly how I needed it too thank you
- ajaybabuinturi
Super User
Hi Kate_McCulloch,
I add two more rows to the sample data to get the actual Count. Try with below DAX.Total Cost Accommodation Count by Family = COUNTROWS( DISTINCT( SELECTCOLUMNS('Table', "FamilyID", 'Table'[Family_ID], "Cost", 'Table'[Total Cost Accommodation]) ) )
SampleData:
Result:Thanks,
If you found this solution helpful, please consider giving it a Likeš and marking it as Accepted Solutionā. This helps improve visibility for others who may be encountering/facing same questions/issues.