Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SINGHTX9
Helper II
Helper II

Urgent help needed with groupby and distinct count

Hi All

 

Please, can anyone really help me to solve my issue. I have already posted my issue few time but no one could give me a solution.Actual dataActual dataMatrix dataMatrix data

 

I have the records for a laboratory receiving two type of tests: CC or IA.

So each Accession ID can have:

  • CC tests only
  • IA tests only
  • CC IA tests both 
  • No tests

So i want to unpivot the test type column but doing transpose doesnt help me.

 i tried to create a matrix table (Attached pic) so as you can see it returns the count of "CC" and "IA" tests, but my end goal is to 

get a tabel with 

 

Accession ID     CC    IA

 

and the columns CC and IA should have only binary number i.e if that accession ID has "CC" tests then return 1 else 0. Similarly with IA tests. I dont care about the number, all i care is whether the accession ID has the "CC" test ordered or not.

End resultEnd result

2 ACCEPTED SOLUTIONS

Also I had alreday creating the two columns CC and IA using If statements as you had suggested above but this was the result i got. As expected it was missing IA and CC common accesion id and returning it as zero

 

Venn diagram using the IF statements.png

View solution in original post

Anonymous
Not applicable

Okay. Then after creating the CC and IA columns, you create one calculated table called "FinalTable" with the following expression.

 

FinalTable = ADDCOLUMNS(DISTINCT(ActualData[AccessionID]),"CCS",sumx(RELATEDTABLE(ActualData),ActualData[CC]),"IAS",SUMX(RELATEDTABLE(ActualData),ActualData[IA]))

This will create the table as per your requirement.

View solution in original post

14 REPLIES 14

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.