Forum Discussion
Measure to group and count rows
I have data that is structured like this:
| M-ID | S-ID | EnteredBy |
| M-1 | S1 | C |
| M-1 | S2 | C |
| M-1 | S3 | C |
| M-1 | S4 | C |
| M-2 | S1 | C |
| M-2 | S2 | D |
| M-2 | S3 | NE |
| M-3 | S1 | C |
| M-3 | S2 | D |
| M-3 | S3 | D |
| M-3 | S4 | D |
| M-3 | S5 | D |
| M-3 | S6 | D |
I have a measure that provides a grouping by enteredby value: Entered By Group = If(ISBLANK(Table1[Entered]),"Not Entered", If(Find("D",TMSShipmentDetail[EnteredBy],1,99)<>99,"D-group,"C-group"))
I would like to add another measure to count at the M-ID level. So I can get a count showing all S-IDs entered by C or not all S-IDs entered by C. So for the example data above the table would look like this:
| Count of M-IDs | Grouping |
| 1 | All S-ID entered by C-group |
| 2 | Not All S-IDs entered by C Group |
- Anonymous1 year ago
Hi TomSinAA ,
First create an enter table:
Then please create this measure:
Count of M-IDs = VAR __table = SUMMARIZE('Table1','Table1'[M-ID],'Table1'[S-ID],"@EnteredBy",[Entered By Group]) VAR __c_sid = CALCULATETABLE(VALUES(Table1[S-ID]),FILTER(__table,[@EnteredBy]="C")) VAR __not_c_sid = CALCULATETABLE(VALUES(Table1[S-ID]),FILTER(__table,[@EnteredBy]<>"C")) VAR __only_c_count = COUNTROWS(EXCEPT(__c_sid,__not_c_sid)) VAR __not_only_c_count = COUNTROWS(EXCEPT(__not_c_sid,__c_sid)) VAR __result = IF(SELECTEDVALUE('Table'[Grouping])="All S-ID entered by C-group",__only_c_count,__not_only_c_count) RETURN __resultOutput:
Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
2 Replies
- parry2k
Super User
TomSinAA you are looking for dynamic segmentations, there are many solutions to this, check out one blog post here and this will get you started.
- AnonymousNot applicable
Hi TomSinAA ,
First create an enter table:
Then please create this measure:
Count of M-IDs = VAR __table = SUMMARIZE('Table1','Table1'[M-ID],'Table1'[S-ID],"@EnteredBy",[Entered By Group]) VAR __c_sid = CALCULATETABLE(VALUES(Table1[S-ID]),FILTER(__table,[@EnteredBy]="C")) VAR __not_c_sid = CALCULATETABLE(VALUES(Table1[S-ID]),FILTER(__table,[@EnteredBy]<>"C")) VAR __only_c_count = COUNTROWS(EXCEPT(__c_sid,__not_c_sid)) VAR __not_only_c_count = COUNTROWS(EXCEPT(__not_c_sid,__c_sid)) VAR __result = IF(SELECTEDVALUE('Table'[Grouping])="All S-ID entered by C-group",__only_c_count,__not_only_c_count) RETURN __resultOutput:
Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly -- How to provide sample data in the Power BI Forum