cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
marama
Helper I
Helper I

Concatanate top X results with percentage of total, in a sting

Hello.

So i have a list of activities an employee has been working on. For example:

2021-12-01 User1 Project1    3.5hrs

2021-12-01 User1 Project2   2.2hrs

2021-12-01 User2 Project1.   4hrs

...

My matrix visual has users in rows, weeks/monts as columns, and hrs as values. Now I'd also like to have a string value (per user per timeframe) in column with this data:

"Project1: 80%, Project2: 15%, Project3: 5".

I'm new to Power BI, so I have a rough idea I probably nee to work with measures to achieve that.

I know I can have a tooltip with table to show more data, but I really need to have the information at matrix level, without havin to hover over the values.

Any idea how to solve my issue?

Thank you

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @marama 

You can use CONCATENATEX in a measure to concatenate the Project % string for the top projects.

 

As an example, in the sample PBIX (attached) I created a measure as follows

Hours Percentage by Project Text = 
VAR ProjectLimit = 3
VAR TotalHours = [Hours Sum]
VAR ProjectPct =
    ADDCOLUMNS (
        SUMMARIZE ( Activites, Activites[Project] ),
        "@Pct", DIVIDE ( [Hours Sum], TotalHours )
    )
VAR ProjectPctTop =
    TOPN ( ProjectLimit, ProjectPct, [@Pct] )
RETURN
    CONCATENATEX (
        ProjectPctTop,
        Activites[Project] & ": "
            & FORMAT ( [@Pct], "0%" ),
        ", "
    )

Note that [Hours Sum] is a measure summing hours.

 

Is this the sort of thing you're looking for?

 

Regards,

Owen


Owen Auger

Did I answer your question? Mark my post as a solution!

My Blog
Connect on Twitter
Connect on LinkedIn

View solution in original post

5 REPLIES 5
OwenAuger
Super User
Super User

Hi @marama 

You can use CONCATENATEX in a measure to concatenate the Project % string for the top projects.

 

As an example, in the sample PBIX (attached) I created a measure as follows

Hours Percentage by Project Text = 
VAR ProjectLimit = 3
VAR TotalHours = [Hours Sum]
VAR ProjectPct =
    ADDCOLUMNS (
        SUMMARIZE ( Activites, Activites[Project] ),
        "@Pct", DIVIDE ( [Hours Sum], TotalHours )
    )
VAR ProjectPctTop =
    TOPN ( ProjectLimit, ProjectPct, [@Pct] )
RETURN
    CONCATENATEX (
        ProjectPctTop,
        Activites[Project] & ": "
            & FORMAT ( [@Pct], "0%" ),
        ", "
    )

Note that [Hours Sum] is a measure summing hours.

 

Is this the sort of thing you're looking for?

 

Regards,

Owen


Owen Auger

Did I answer your question? Mark my post as a solution!

My Blog
Connect on Twitter
Connect on LinkedIn

BTW, any way to have the string list of projects sorted from highest percentage to lowest?

Glad it worked 🙂

 

Sure, actually I omitted the "order by" arguments of CONCATENATEX (4th argument onwards). These come in pairs, being an Order By Expression and Order (ASC/DESC).

See dax.guide for more detail 🙂

 

In this example, we can update the measure to order by [@Pct] descending by adding two arguments to CONCATENATEX:

 

 

Hours Percentage by Project Text = 
VAR ProjectLimit = 3
VAR TotalHours = [Hours Sum]
VAR ProjectPct =
    ADDCOLUMNS (
        SUMMARIZE ( Activites, Activites[Project] ),
        "@Pct", DIVIDE ( [Hours Sum], TotalHours )
    )
VAR ProjectPctTop =
    TOPN ( ProjectLimit, ProjectPct, [@Pct] )
RETURN
    CONCATENATEX (
        ProjectPctTop,
        Activites[Project] & ": "
            & FORMAT ( [@Pct], "0%" ),
        ", ",
        [@Pct],
        DESC
    )

 

Regards,

Owen


Owen Auger

Did I answer your question? Mark my post as a solution!

My Blog
Connect on Twitter
Connect on LinkedIn

Word perfectly, thank you!!!

Wow, I'm impressed. Works perfectly,thank you

Helpful resources

Announcements
Power BI Show Ep 4 Post Show Carousel.jpg

The Power BI Community Show

Shabnam Watson demos Incremental refresh & Hybrid Tables and Leila Etaati demos Charticulator.

PBI April Release 2022 768x460.png

Check it out!

Click here to read more about the April 2022 updates!

Power BI Dev Camp Session 22 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!