SOLVED

Counting the number of Diagnosis codes by context ,Specialty and provider-HelpwithPowerQuery/formula

%3CLINGO-SUB%20id%3D%22lingo-sub-2333798%22%20slang%3D%22en-US%22%3ECounting%20the%20number%20of%20Diagnosis%20codes%20by%20context%20%2CSpecialty%20and%20provider-HelpwithPowerQuery%2Fformula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2333798%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EHi%20Team%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EHope%20you%20are%20doing%20well!...%20I%20am%20trying%20to%20count%20the%20number%20of%20diagnosis%20codes%20by%20context%20%2CSpecialty%20and%20provider..Can%20you%20please%20help%20me%20here..Attached%20the%20Input%20and%20the%20output%20required%20sheets....%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EAppreciate%20your%20help!%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EThanks%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EArun%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2333798%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPower%20BI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2334395%22%20slang%3D%22en-US%22%3ERe%3A%20Counting%20the%20number%20of%20Diagnosis%20codes%20by%20context%20%2CSpecialty%20and%20provider-HelpwithPowerQuery%2Ffor%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2334395%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F216929%22%20target%3D%22_blank%22%3E%40Arun%20Chandramouli%3C%2FA%3E%26nbsp%3BPlease%20see%20the%20attached%20file%20containing%20a%20PQ%20solution%20in%20the%20Output%20sheet.%20I%20have%20also%20noticed%20some%20discrepancies%2C%20probably%20caused%20by%20the%20fact%20that%20you%20created%20the%20example%20output%20manually.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20query%20is%20fairly%20standard%2C%20except%20for%20one%20little%20trick%20that%20allows%20you%20to%20split%20the%20%22Diagnosis%20code%22%20column%20based%20on%20the%20maximum%20number%20of%20elements%20in%20any%20given%20field.%20I%20picked%20it%20up%20from%20a%20video%20by%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3Bnot%20too%20long%20ago.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexcel%2Fbe-careful-when-splitting-cells-in-power-query%2Fm-p%2F11307%22%20target%3D%22_self%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexcel%2Fbe-careful-when-splitting-cells-in-power-query%2Fm-p%2F11307%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2334616%22%20slang%3D%22en-US%22%3ERe%3A%20Counting%20the%20number%20of%20Diagnosis%20codes%20by%20context%20%2CSpecialty%20and%20provider-HelpwithPowerQuery%2Ffor%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2334616%22%20slang%3D%22en-US%22%3ERiny_van_Eekelen%20%3A%20Really%20appreciate%20your%20response!..Thank%20you%20very%20much%20for%20your%20help...%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2334725%22%20slang%3D%22en-US%22%3ERe%3A%20Counting%20the%20number%20of%20Diagnosis%20codes%20by%20context%20%2CSpecialty%20and%20provider-HelpwithPowerQuery%2Ffor%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2334725%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3BWill%20keep%20that%20in%20mind%20for%20next%20time%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2334880%22%20slang%3D%22en-US%22%3ERe%3A%20Counting%20the%20number%20of%20Diagnosis%20codes%20by%20context%20%2CSpecialty%20and%20provider-HelpwithPowerQuery%2Ffor%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2334880%22%20slang%3D%22en-US%22%3EHi%20Riny%2CJust%20one%20more%20question%3A%20If%20I%20want%20to%20count%20a%20diagnosis%20code%20only%20once%20per%20row%20irrespective%20of%20the%20number%20of%20times%20it%20appears%20in%20a%20row%20and%20the%20arrive%20at%20the%20count%20stats%20..Can%20you%20please%20help%20me%20with%20that...%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi Team,

Hope you are doing well!... I am trying to count the number of diagnosis codes by context ,Specialty and provider..Can you please help me here..Attached the Input and the output required sheets....

Appreciate your help!



Thanks,
Arun

9 Replies
best response confirmed by Arun Chandramouli (Occasional Contributor)
Solution

@Arun Chandramouli Please see the attached file containing a PQ solution in the Output sheet. I have also noticed some discrepancies, probably caused by the fact that you created the example output manually.

 

The query is fairly standard, except for one little trick that allows you to split the "Diagnosis code" column based on the maximum number of elements in any given field. I picked it up from a video by @Wyn Hopkins not too long ago. 

https://techcommunity.microsoft.com/t5/excel/be-careful-when-splitting-cells-in-power-query/m-p/1130... 

Riny_van_Eekelen : Really appreciate your response!..Thank you very much for your help...

Thanks for the reference @Riny_van_Eekelen 

There's actually a simpler way using Split Text to Rows option under Advanced

 

 

image.png

 

 

Hi Riny,Just one more question: If I want to count a diagnosis code only once per row irrespective of the number of times it appears in a row and the arrive at the count stats ..Can you please help me with that...

@Arun Chandramouli Not sure I follow. You mean that if, for instance, E1 in the table has two entries for the same diagnose, you only want to count it once?

 

Hi Riny, Yes I meant the same...At a row level if a diagnosis code is present twice or thrice I want to count it only once...

@Arun Chandramouli Okay. Then try the attached version. I just entered an extra code on the first row and it only counts once in the output. Have also simplified the query using Wyn's tip. Also added a Trim step, that will get rid for any trailing or leading spaces in the diagnose column.