Creating a dimension calculated field from a numeric field and using it in a bar chart

I have a dataset with 2 fields:
accession_ID Patient_ID
123 555
123 555
123 555
321 666
363 787
363 787
899 565
899 565
899 565
899 565

I want to create a histogram or a bar chart that will show me the distinct count of tests for each patient. I also want the distinct count of tests to show as buckets (a dimension). For example, 1-10, 11-15, 16-21, etc… How can I create a dimension using the distinct count of accessions and then use that field in a visual. I have tried to create it with if/else and LAC but it did not work. Additionally, bar charts and histograms do not have the flexibility to accept dimensions in place of measures.

I want a bar chart to look like this:

Hi @huda.h.yazgi Thanks for posting your question. :slight_smile: I am pinging one of our SAs to make sure your question gets a reply on Monday if we don’t hear back from the community before then. Thx!

Hello @huda.h.yazgi !

Can you send some of the ifelse and LAC calculations that you tried that didn’t work? In the past I have been able to create dimensions from ifelse statements with date fields so this should work. Have you tried something like the following?:

calc1 = distinct_count({accession_ID}, [{Patient_ID}])

calc2 =

ifelse(
         {calc1} <= 1 OR {calc1} => 5,
         '1-5',
         {calc1} <= 6 OR {calc1} => 10,
         '6-10',
         etc...,
 NULL)

Let me know if you tried that and if so if it threw an error!

Hello @huda.h.yazgi !

Were you able to try the calculation I posted above, and if it worked could you mark the comment as a solution to help the community?