Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
EmericTms
Frequent Visitor

Creation of a matrix based on existing values and categorizing non-existing values

Hello,

 

I would like your help regarding the creation of a specific matrix in power bi.

I created an simple excel to better explain my issue :

EmericTms_0-1739873892304.png

 

I have a table with 3 columns. And I would like to have a power bi matrix that takes the column "Entreprise" as lines, the column "Chapitre" as columns, and for the values : 1 is the status from the column "statut" is "Commencé", 2 if it is "En cours", 3 is it is "En retard".
But I also want to have 4 if for the "Entreprise" there is no "chapitre". For example, I would like my matrix to show 4 for "Entreprise" : "HP" and "Page" = "3" because it is not present in the table but it is still relevant for me.

This I can do.

 

What I can't manage to do is adding the fact that some precise combinations are Non Applicable. For example, "Apple" and chapitre "4" are not applicable and so is "Microsoft" and chapitre "3", and for these 2 I would like the matrix to have the value 5 and not 4. 

Do you know if it is possible ?

 

Thank you for your help !

 

Best regards,

ET

1 ACCEPTED SOLUTION
v-denglli-msft
Community Support
Community Support

Thanks for the reply from rajendraongole1, please allow me to provide another insight.

Hi @EmericTms ,

 

Please refer to the following steps.

The data table is as follows.

vdengllimsft_0-1739942910294.png

 

Creates a disconnected table with a single column. Contains distinct values of the 'Chapitre' column.

 

DisconnectedTable = VALUES('Table'[Chapitre])

 

vdengllimsft_2-1739943346980.png

 

Create the following measure as the value of the matrix.

 

Measure = 
VAR current_enterprise = SELECTEDVALUE('Table'[Enterprise]) --The current cell's Enterprise.
VAR current_statut = CALCULATE(SELECTEDVALUE('Table'[Statut]), 'Table'[Chapitre] = SELECTEDVALUE('DisconnectedTable'[Chapitre])) --The current cell's Statut.
RETURN
IF(current_statut <> BLANK(), 
    SWITCH(current_statut,
        "Commencé", 1,
        "En cours", 2,
        "En retard", 3
    ),
    SWITCH(current_enterprise, --If current_statut is blank it means that this combination is not applicable.
    "HP",4,
    "Page", 4,
    "Microsoft",5,
     "Apple", 5
    )
)

 

 

Use Enterprise as the rows of the matrix, the field of the disconnected table as the columns of the matrix, and the measure as the matrix value.

vdengllimsft_1-1739943286281.png

Hopefully it will meet your needs.

 

Please see the attached pbix for reference.

 

Best Regards,
Dengliang Li

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

View solution in original post

6 REPLIES 6
v-denglli-msft
Community Support
Community Support

Thanks for the reply from rajendraongole1, please allow me to provide another insight.

Hi @EmericTms ,

 

Please refer to the following steps.

The data table is as follows.

vdengllimsft_0-1739942910294.png

 

Creates a disconnected table with a single column. Contains distinct values of the 'Chapitre' column.

 

DisconnectedTable = VALUES('Table'[Chapitre])

 

vdengllimsft_2-1739943346980.png

 

Create the following measure as the value of the matrix.

 

Measure = 
VAR current_enterprise = SELECTEDVALUE('Table'[Enterprise]) --The current cell's Enterprise.
VAR current_statut = CALCULATE(SELECTEDVALUE('Table'[Statut]), 'Table'[Chapitre] = SELECTEDVALUE('DisconnectedTable'[Chapitre])) --The current cell's Statut.
RETURN
IF(current_statut <> BLANK(), 
    SWITCH(current_statut,
        "Commencé", 1,
        "En cours", 2,
        "En retard", 3
    ),
    SWITCH(current_enterprise, --If current_statut is blank it means that this combination is not applicable.
    "HP",4,
    "Page", 4,
    "Microsoft",5,
     "Apple", 5
    )
)

 

 

Use Enterprise as the rows of the matrix, the field of the disconnected table as the columns of the matrix, and the measure as the matrix value.

vdengllimsft_1-1739943286281.png

Hopefully it will meet your needs.

 

Please see the attached pbix for reference.

 

Best Regards,
Dengliang Li

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

Hello,

Thank you for the response. After a few modifications it seems to be working ! But on the same idea, there is a matrix that I can't get to work with the formula you sent, could you also help me with this one too? (sorry I'm struggling with Power BI). 

I have these two tables (same format as before but different names), they are related through the id of the first table.

EmericTms_0-1740504668891.png

EmericTms_1-1740504689767.png

I created the first matrix as you instructed me and it works : 

EmericTms_2-1740504801121.png

 

but I can't manage to make this one works :

EmericTms_3-1740504865420.png

Do you have an idea how to make it work?

Here is the power bi with the tables, the matrix and the formula :

test pbi 

Thank you.

ET

 

Hi @EmericTms ,

 

Please try the following measure.

Measure 2 = 
VAR current_chapter = MAX('Tableau2'[Chapter])
VAR current_company = CALCULATE(SELECTEDVALUE(Tableau1[Company]),REMOVEFILTERS(Tableau2))
VAR current_score = MAX(Tableau1[Score])
RETURN
IF(current_score <> BLANK(), 
    SWITCH(current_score,
        1, 1,
        2, 2,
        3,3
    ),
    SWITCH(SELECTEDVALUE('DisconnectedTable'[Chapter]),
        "4b",SWITCH(current_company, "Apple", 4, 5), 
        "1a",SWITCH(current_company, "Tesla", 4, 5),
        5
    )
)

 

vdengllimsft_0-1740556522202.png

 

Please see the attached pbix for reference.

 

Best Regards,
Dengliang Li

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

Thank you, I accepted the previous answer as the solution !

rajendraongole1
Super User
Super User

Hi @EmericTms  - Yes! You can achieve this in Power BI by creating a calculated measure that assigns the correct values based on the different conditions you specified. 

 

create a measure as below:

Status_Value =
VAR _Status = SELECTEDVALUE('Table'[Statut])
VAR _Entreprise = SELECTEDVALUE('Table'[Entreprise])
VAR _Chapitre = SELECTEDVALUE('Table'[Chapitre])

-- Define Non Applicable Cases
VAR _NonApplicable =
OR(
(_Entreprise = "Apple" && _Chapitre = 4),
(_Entreprise = "Microsoft" && _Chapitre = 3)
)

RETURN
SWITCH(
TRUE(),
_Status = "Commencé", 1,
_Status = "En cours", 2,
_Status = "En retard", 3,
_NonApplicable, 5, -- Assign 5 for Non Applicable cases
4 -- Default to 4 for missing Chapitre-Entreprise pairs
)

 

 

check it and let know.

 





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

Proud to be a Super User!





Hello, thank you for the answer. I tried it, but it is not working, everything return as 4 and I have no 5. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.