How to sort pivot based on measure and create a stacked bar chart

Hi Everyone,

I am trying to create a stacked bar chart between 2 dimensions (one being week, other is a string - more below) and 1 measure. I am new to Looker

But in order to get the stacked bar chart I figure that I need to

  • Create a pivot
  • Transpose the data
  • Create stacked bar chart
    I am stuck with step 2 and 3.

The above steps is what I have thought could help me arrive at the visualization I want but would appreciate if there is any other solution for this.

Scenario:
I have a digital marketing data with me, where I am trying to create a visualization on ‘Leads’ generated,

I have 2 dimensions, 1 measure

  1. Lead Created Week - Week on which a lead was created
  2. Reason2 - reason a lead was created or what reason attracted the user most
  3. Leads - count of leads

I have plotted the below visualization where I have created a pivot of week with Reason2 and Lead count under it and have plotted it on a stacked bar chart (as below).

Where each bar is a Reason (X-axis) and each color is the Week dimension, leads (count of leads) is in the Y-axis

Even though this is help what would be helpful is having ‘Week’ on X-axis, ‘Leads’ (count of leads) on Y-axis and ‘Reasons2’ dimension as a legend.

There is also one catch i.e., there are more than 100 distinct values in ‘Reason2’ field but I need to pick on Top 10 Reasons (i.e., the reasons that generated the most leads), which in the above screenshot I have achieved by limiting the display rows to 10 as the measure was already sorted.

I tried to flip around the pivot by having reason in pivot and Week as dimension, but if now the pivot is sorted in alphabetical manner and not by value of measures (screenshot below), I need the top 10 reasons which most leads per week.

Unable to attach the second screenshot due to new users restriction, would try to attach as a reply to the post.

How do I achieve the desired visualization of having week on X-axis with leads on Yaxis but only the top 10 Reasons should be generated.

0 1 1,752
1 REPLY 1

Second screenshot as mentioned in the above post.

Top Labels in this Space