Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Help with Cross Tab

mtatum
6 - Meteoroid

Hello,

I have always struggle to understand how to use the Cross Tab tool to get the results that I desire.  Would somebody be willing to show me how get to the top format  using the data from the the bottom format?  It's different data, but the same formats.  I appreciate any help that you can give to help me understand. 

Thanks!

Mary

Final Output.png

 

Horizontal Data.png

5 REPLIES 5
griffinwelsh
12 - Quasar

Alteryx really does not play nicely with merged cells or duplicate header names. You can make this format in your output by writing to an excel file in batches but really it is better practice to just use unique headers and not merge cells.

Qiu
21 - Polaris
21 - Polaris

@mtatum 
Parsing non-structured data is alway challenging and case-by-case.
Can you share some sample data?

Yoshiro_Fujimori
15 - Aurora

Hi @mtatum ,

 

Alteryx is good at dealing with normalized data.

So it is not easy to output Excel-like pivot table which contains merged cells.

But if the table header can be "flattened" to one row, here is one solution.

 

Input Data

I changed the "Month" from char ("Mar", "Apr") to numbers (3, 4) as the Cross Tab sorts the columns in alphabetic order.

CPTCharge DescriptionVisitsCharge CountYearMonth
1aaa5620233
2bbb4720233
3ccc3820233
4ddd2920234
5eee11020234

 

Workflow

Sample_Pivot_workflow.png

Formula

Name2 = ToString([Year]) + " " + PadLeft(ToString([Month]), 2, "0") + " " + [Name]

 

Output Data

If you stick to the Month in char, you may want to try Dynamic Rename Tool after Cross Tab.

CPTCharge Description2023_03_Charge_Count2023_03_Visits2023_04_Charge_Count2023_04_Visits
1aaa65  
2bbb74  
3ccc83  
4ddd  92
5eee  101

 

I hope this helps. Good luck.

[deleted]

CoG
13 - Pulsar

There are a few rules of thumb when it comes to using the Cross Tab Tool:

  1. You can only "Pivot" 2 columns. The distinct rows of the first column will become the new column names, and the second column will distribute its values across those newly created columns (called buckets henceforth).
  2. If multiple rows exist that fall into the same bucket, then they will be aggregated via the method of your choosing (making sure you are working with the right datatype)
  3. Values that you do not want aggregated must be "grouped" by other columns that distinguish between those records
  4. This tool replaces all special characters (including spaces) with underscores
  5. It will sort the new columns alphabetically

In your case, Rule 1 prohibits the immediate use of a single Cross Tab tool to achieve the desired results (*There are work arounds for this).

Considering Rule 2, I have assumed you would just use sum (if you can guarantee that only 1 value will ever appear for a given CPT and month/year combo, you still need to select an aggregation method, but it doesn't matter which you choose, although it is best practice to account for the case where you will need to aggregate).

Based on your input/output, grouping should occur on CPT & Charge Description (Rule 3)

Rule 4 is just an unfortunate and unavoidable side effect of the Cross Tab Tool.

Rule 5 requires that you either set up a sorting prefix to ensure proper formatting, or you hard code via Select Tool a column rearrangement.

 

To get your input and output I will showcase 2 options the simple way and the smart way.

 

Simple: Use 2 Cross Tabs, one for each segment of the data, and join the data back together on CPT code

Screenshot.png

 

Smart: Utilize Transpose Tool first to collapse Both Value columns into a single column, then Cross Tab

Screenshot.png

 

Hope this helps & Happy Solving!

Labels