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
gk2go
Helper II
Helper II

Bar chart grouping by one field but labeling with another

Suppose I have this table:Screen Shot 2019-07-14 at 22.11.33.png

 

I want to create a bar chart like this one (view by url), but instead of displaying the URL I want to display the page name as the axis labels (so as if view by title but with the values of view by url).

Screen Shot 2019-07-14 at 22.12.45.png

The problem is that there are multiple titles per URL, so the issue is which one to choose. It could be the first. How to accomplish this neatly in Power BI?

 

I've uploaded groupby-url-display-title.pbix 

15 REPLIES 15
Ashish_Mathur
Super User
Super User

Hi,

Please show your exact expected result.  Just show your expected result in a Table.  Thereafter we can always switch the Table to a column/bar visual.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Anonymous, your measure selects the right labels/titles, but gives 4 views for the abc.html, it should be 8.

 

Capture.PNG

 

@Ashish_Mathur 

Title                              | Path                                                |  Views

ABC Super Super Title  | www.example.com/abc.html          | 8

DEF Title                       | www.example.com/def                   | 2 

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

This doesn't work. You've only stripped parts of the URL and not used the dynamic_title at all.

Instead of abc and def as rows, you should have ABC Super Super Title and DEF Title as shown in my table above.

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you @Ashish_Mathur .

This worked but on a large table it takes forever to run. I've kept it running a server for over 24 hours and then aborted it as it showed it was still at ~10% of the rows. Isn't there a more efficient solution?

 

Your solution:

    Partition = Table.Group(#"Changed Type", {"URL"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Title", "Views", "Index"}, {"Title", "Views", "Index"}),
    #"Grouped Rows" = Table.Group(#"Expanded Partition", {"URL"}, {{"Max index for that URL", each List.Max([Index]), type number}}),
    Joined = Table.Join(#"Expanded Partition", "URL", #"Grouped Rows", "URL"),
    #"Added Custom" = Table.AddColumn(Joined, "Title to be considered", each if [Index] = [Max index for that URL] then [Title] else null),
    #"Sorted Rows" = Table.Sort(#"Added Custom",{{"URL", Order.Ascending}, {"Index", Order.Descending}, {"Max index for that URL", Order.Descending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"Title to be considered"}),
    #"Removed Columns" = Table.RemoveColumns(#"Filled Down",{"Index", "Max index for that URL"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Views", type number}})

Sorry, i would not know.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-diye-msft
Community Support
Community Support

Hi 

 

Not sure if you’d like to show the chart as below, similar with view by url but replace the url with the first title:

06.png

If so, you can use group. Right click the title and group, change the display name using the first title.

07.png

Pbix attached: https://wicren-my.sharepoint.com/:u:/g/personal/dinaye_wicren_onmicrosoft_com/EZ9YBANxgdpNtg3yU9CGR2...

 

Best regards,

Dina Ye

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Anonymous
Not applicable

Hi @gk2go  , 

Create a new column:

Column = CALCULATE( MIN( Table1[Title] ) , ALLEXCEPT( Table1 , Table1[URL] ))

Let me know if that helps,
Cheers
Robin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @Anonymous . That worked until i introduce a row with an empty title:Screen Shot 2019-07-15 at 07.40.11.png

 

Then blank wins:Screen Shot 2019-07-15 at 07.40.16.png

How to make sure it's not blank that shows up? Can the non-blank title with the highest views be the one selected? 

Anonymous
Not applicable

Hi @gk2go  ,

Try adding Table1[Title] <> BLANK() as below:

Column = CALCULATE( MIN( Table1[Title] ) , ALLEXCEPT( Table1 , Table1[URL] ), Table1[Title] <> BLANK() )

Let me know if that works.
Cheers,
Robin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Anonymouscan you make this pick the non-blank title with the highest views?

Anonymous
Not applicable

Hi @gk2go  , 

No worries , here it is:

 

Measure = IF( CALCULATE( MAX( Table1[VIEWS] ) , ALLEXCEPT( Table1 , Table1[URL] ) , Table1[TITLE] <> BLANK() ) = MAX( Table1[VIEWS]) , MAX( Table1[TITLE]) , BLANK() )

Capture2.JPG
Cheers,
Robin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It's not working as expected, see: Capture.PNG

 

Anonymous
Not applicable

Hi @gk2go ,

I would suggest to use the Measure as a filter only:

Measure = IF( CALCULATE( MAX( Table1[VIEWS] ) , ALLEXCEPT( Table1 , Table1[URL] ) ,Table1[TITLE] <> BLANK() ) = MAX( Table1[VIEWS]) , 1 , BLANK() )

Capture7.JPG

Please try the same as screenshot and let me know if that suits.
Cheers, 
Rob

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.