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
Anonymous
Not applicable

Averages by String

Hello,

 

I am trying to find an average based on a string value. Here is a little background information:

1. I am trying to find the average days residents spend during their time in a residence

2. Residents can live in apts, townhomes, villas or houses

3. I got the data to show their "path" and the "number of days" they spent at each place, so the data looks like this:

 

Resident IDPathDays in Each Path
1Apt, Townhome, House385, 400, 600
2Villa, House365, 500
3Apt, Townhome, House400, 90, 285
4Townhome, Villa, House200, 160, 390
5Apt, Townhome, House90, 180, 400

 

Now, I am trying to get an average number of days in each location, so I would want to average the days that resident 1, 3, and 5 had together. My goal table would look like this

PathNumber of Residents

Average Days in each Residence

Apt, Townhome, House3291, 233, 428
Villa, House1365, 500
Townhome, Villa, House1200, 160, 390

 

Any help would be much appreciated!!

 

Thank you!

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Anonymous 

I have shared a sample PBIX here.

 

I would recommend you transform your data into this form to make the calculations easier:

 

Resident IDPath DescriptionPathItemTypeDays
1Apt, Townhome, House1Apt385
1Apt, Townhome, House2Townhome400
1Apt, Townhome, House3House600
2Villa, House1Villa365
2Villa, House2House500
3Apt, Townhome, House1Apt400
3Apt, Townhome, House2Townhome90
3Apt, Townhome, House3House285
4Townhome, Villa, House1Townhome200
4Townhome, Villa, House2Villa160
4Townhome, Villa, House3House390
5Apt, Townhome, House1Apt90
5Apt, Townhome, House2Townhome180
5Apt, Townhome, House3House400

 

I have done this in Power Query in the above PBIX.

 

Then create measures:

 

Number of Residents = 
DISTINCTCOUNT ( Residence[Resident ID] )

Average Days = 
AVERAGE ( Residence[Days] )

Average Days Concatenated = 
IF ( 
    HASONEVALUE ( Residence[Path Description] ), // ensure just one Path Description is selected
    CONCATENATEX ( 
        VALUES ( Residence[PathItem] ),
        ROUND( [Average Days], 0),
        ", ",
        Residence[PathItem]
    )
)

 

 

After doing this, you can create a table similar to the one you posted:

 

image.png

Anyway that is how I would approach this. Hopefully that's of some use 🙂

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @Anonymous 

I have shared a sample PBIX here.

 

I would recommend you transform your data into this form to make the calculations easier:

 

Resident IDPath DescriptionPathItemTypeDays
1Apt, Townhome, House1Apt385
1Apt, Townhome, House2Townhome400
1Apt, Townhome, House3House600
2Villa, House1Villa365
2Villa, House2House500
3Apt, Townhome, House1Apt400
3Apt, Townhome, House2Townhome90
3Apt, Townhome, House3House285
4Townhome, Villa, House1Townhome200
4Townhome, Villa, House2Villa160
4Townhome, Villa, House3House390
5Apt, Townhome, House1Apt90
5Apt, Townhome, House2Townhome180
5Apt, Townhome, House3House400

 

I have done this in Power Query in the above PBIX.

 

Then create measures:

 

Number of Residents = 
DISTINCTCOUNT ( Residence[Resident ID] )

Average Days = 
AVERAGE ( Residence[Days] )

Average Days Concatenated = 
IF ( 
    HASONEVALUE ( Residence[Path Description] ), // ensure just one Path Description is selected
    CONCATENATEX ( 
        VALUES ( Residence[PathItem] ),
        ROUND( [Average Days], 0),
        ", ",
        Residence[PathItem]
    )
)

 

 

After doing this, you can create a table similar to the one you posted:

 

image.png

Anyway that is how I would approach this. Hopefully that's of some use 🙂

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
Anonymous
Not applicable

Thanks Owen!! This worked perfectly!

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.

Top Solution Authors