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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
york
Helper I
Helper I

How to calculate if the data is in the multiple columns

Hi guys:

       Like below table, operator will inspect the product every day, and they will record the defects they found in column Defect 1~4

Inspection DateDefect 1Defect 2Defect 3Defect 4
2023/1/1Box BrokenSoldering FailLow BatteryProduct Scratch
2023/1/2Low batteryProduct Scratch  
2023/1/3Product broken Low battery  
2023/1/4Cable Disconnected   

     Then I want to create a chart that shows the data, such as how many types of defects are found, how many times each defect is found, and the trend by date of each defect type, could you help check how to meak it?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @york ,

 

@jennratten 's solution is done in Power Query and the key is to unpivot columns.

vstephenmsft_0-1681464460361.png

Click "Transform data" to go to Power Query Editor.

In Power Query, select the below four columns at the same time and click "Unpivot Columns".

15.png

And then the four columns are converted to a Attribute column and a Value column.

vstephenmsft_1-1681464536053.png

Then click "Close&Apply" to go back to Power BI Desktop, create the below matrix.

vstephenmsft_3-1681464680878.png

vstephenmsft_2-1681464646058.png

 

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @york ,

 

@jennratten 's solution is done in Power Query and the key is to unpivot columns.

vstephenmsft_0-1681464460361.png

Click "Transform data" to go to Power Query Editor.

In Power Query, select the below four columns at the same time and click "Unpivot Columns".

15.png

And then the four columns are converted to a Attribute column and a Value column.

vstephenmsft_1-1681464536053.png

Then click "Close&Apply" to go back to Power BI Desktop, create the below matrix.

vstephenmsft_3-1681464680878.png

vstephenmsft_2-1681464646058.png

 

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

jennratten
Super User
Super User

Hello - I recommend unpivoting the columns like this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY31DdU0lFyyq9QcCrKz07NA3KC83NSUosy89IV3BIzc4ACPvnlCk6JJSWpRZVAXkBRfkppcolCcHJRYklyhlKsDtwoI6jiJJyKdZQUwBhJkzGSsiSYGxRQjcHQZAIUcE5MyklVcMksTs7Py0tNLklNgasEq44FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Inspection Date" = _t, #"Defect 1" = _t, #"Defect 2" = _t, #"Defect 3" = _t, #"Defect 4" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Inspection Date", type date}, {"Defect 1", type text}, {"Defect 2", type text}, {"Defect 3", type text}, {"Defect 4", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Inspection Date"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> " "))
in
    #"Filtered Rows"

jennratten_0-1680515104633.png

You can then add the data to a visual:

jennratten_1-1680515298542.png

 

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

Hi Jenn:

  Thank you very much for your reply, I'm new in Power BI, so I want to know where to input the code that you provided in the Power BI Desktop?

   And I have a table not only contain the columns of the Inspection date, defects, but also the products name, product SKU, inspection result... And I hope the chart can be created in the report view, and the defects may be can be shown in the chart by date/product type/product name...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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