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
harrise-work
New Member

Use distinct measure values as columns in matrix

Hi,

 

There are a few steps to my question, so i will try to be as clear as possible.

 

I have a table that looks like this:

ID_Number      YEAR      MONTH       HOME_CLUB     CLUB_1_VISITS     CLUB_2_VISITS       CLUB_3_VISITS     

1                      2023       Jan                CLUB_1              1                          5                             0                         

1                      2023       Feb               CLUB_1              2                          7                             1                         

1                      2023       Mar               CLUB_1              0                          8                             2                         

2                      2023       Jan                CLUB_2              7                          5                             20                         

2                      2023       Feb               CLUB_2              6                           5                            20                         

2                      2023       Mar               CLUB_2              8                          2                             11                         

 

My goal is to reallocate each person to a different club if more than 60% of their visits are to that club, and I want this to ideally by calculated over a selected time period.

 

For example - if only March was selected:

- person with ID_Number 1 would be reallocated to CLUB_2 (10 visits in total, 8 to CLUB_2 - 80%)

- person with ID_Number 2 would remain at CLUB_3 (21 visits in total - didnt visit any club more than 60%)

 

If Jan, Feb and March were selected:

- person with ID_number 1 would be reallocated to CLUB_2 (26 visits in total, 20 to CLUB_2 - 76%)

- person with ID_number 2 would be reallocated to CLUB_3 (84 visits in total, 51 to CLUB_3 - 61%)

 

I then want to create a matrix where, rows are HOME_CLUB, columns are NEW_CLUB and the values are the number of people that fit that. Everyone should only appear once in the matrix. So for example in Jan, Feb and Mar we would have:

 

                               NEW_CLUB

HOME_CLUB      CLUB_1     CLUB_2     CLUB_3

CLUB_1              0                1               0

CLUB_2              0                0               1

CLUB_3              0                0               0

 

I have created a measure which finds the new club and based on selected values for year and month which is working correctly, I can see this if i create a table/matrix where PERSON_ID is its own column.

 

I also attempted to use the SWITCH method to convert the measure into a column, but this means the club is reallocated for each individual month, rather than for the whole selected period. This means that when for example 3 months are selected, some people are reallocated to a different club in Jan to what they would be for Feb and March and therefore are counted more than once in the matrix. 

 

I am just having trouble with the final step of using the measure value as a column in the matrix, is this possible at all?

 

Any help is appreciated!

3 REPLIES 3
lbendlin
Super User
Super User

yes, all custom matrix visuals are pretty much based on that option  (omitting the column values and using individual meaures instead).  But depending on your scenario this might not be necessary.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

here is some sample data:

 

Person IDMain SiteMonthYearTotal_Visits_to_ClubsClub_1_VisitsClub_2_VisitsClub_3_Visits
1Club_3120232701215
1Club_322023220139
1Club_3320232701413
2Club_212023111100
2Club_222023131300
2Club_232023161600
3Club_1120238710
3Club_1220237170
3Club_1320237700
4Club_212023290029
4Club_222023250025
4Club_232023280028
5Club_312023150105
5Club_32202311182
5Club_3320239054

 

This is where i'm up to in terms of using measures:

https://www.dropbox.com/s/ybjizu04rchzb96/sample%20data.pbix?dl=0 

the measures are used to establish the 'new main club'. The current matrix shows where each person has been reallocated to. You'll notice that if different months are selected there will be some changes to some peoples 'new main club'. The idea is that any months can be selected and based on the selected months the reallocation occurs.

 

What i want to do now is create a matrix where the values in 'Main Club' are the rows and the values returned in 'New main club' are the columns. The values in the matrix will be the number of people in them. For example if only March is selected it will look like this:

 

 Club_1Club_2Club_3
Club_1100
Club_2101
Club_3002

 

But if Jan, Feb and March are selected it will be different:

 

 Club_1Club_2Club_3
Club_1100
Club_2101
Club_3011

 

Hope that makes sense.

Have a look at Page 2. This is done with some unpivoting and implicit measures. No DAX was harmed during the process.

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.