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
katto16
Helper I
Helper I

If it's a specific value in one column, Return the value from the corresponding column

image.png

I have this kind of data table that consists of the test result readings together with the result pass or fail. I'd like to acheive something like

IF [Test 1 P/F] = "fail"

Return [Test 1] 

I'm not sure it's possible to be done in DAX? Another issue is that I have about 70 test parameters so there are gonna be about 70 columns x 2.

 

What I currently have is the unpivoted columns of 70 "Test P/F". Then I created a column called "Failure Mode"

 

Failure Mode = IF('DataUnpivot'[Value]="Fail",'DataUnpivot'[Attribute],BLANK())

 

 Then I created a calculated table,

 

Failure Types = ADDCOLUMNS(SUMMARIZE('DataUnpivot','DataUnpivot'[Serial no.],'DataUnpivot'[Position]),"Failure Type",
CALCULATE(CONCATENATEX('DataUnpivot','DataUnpivot'[Attribute]," ")))

 

 which returns something like this. Serial Numbers with the column name that has the value "fail"

katto16_0-1670902855403.png

 

But as I mentioned above, I want the value of the "Test  " when the "Test  P/F" is "fail". Thanks for any help possible. Appreciate!

 

 

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

Hi @katto16 ,

 

You can achieve this by using Power Query.

Please try:

First create two tables: Table remove Test P/F columns and Unpivot Test columns, Table(2) Remove Test columns and unpivot Test P/F columns.

vjianbolimsft_0-1672384232660.png

vjianbolimsft_1-1672384250138.png

Then filter Table(2) and add a custom column, here is the M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc+7DoAgDEDRf2HW0hbqY3RxdicMjiZu/n8iNUZCkAluSU5KCIZMZ8iSZWRO12Uh0hGDSDq2/brSgUBzrh4BXSNjFwzXJD9IIWIpOtdIFV0tPiMQzXU/zky+pVv5Rirpa1JHAuPc2jLV8F8KSg3K9+u84lQI5dtXMd4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Position = _t, #"Test Dates" = _t, #"Serial no." = _t, #"Test 1" = _t, #"Test 1 P/F" = _t, #"Test 2" = _t, #"Test 2 P/F" = _t, #"Test 3" = _t, #"Test 3 P/F" = _t, #"Test 80" = _t, #"Test 80 P/F" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Position", Int64.Type}, {"Test Dates", type date}, {"Serial no.", type text}, {"Test 1", type number}, {"Test 1 P/F", type text}, {"Test 2", type number}, {"Test 2 P/F", type text}, {"Test 3", type number}, {"Test 3 P/F", type text}, {"Test 80", type number}, {"Test 80 P/F", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Test 1", "Test 2", "Test 3", "Test 80"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Position", "Test Dates", "Serial no."}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] = "Fail")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each Text.Start([Attribute],
Text.Length([Attribute])-4))
in
    #"Added Custom"

Output:

vjianbolimsft_2-1672384354284.png

Then add a custom column in Table then use the custom column to filter Table, after that remove the custom column, now the Table only have the value of the "Test  " when the "Test  P/F" is "fail"

Here is the M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc+7DoAgDEDRf2HW0hbqY3RxdicMjiZu/n8iNUZCkAluSU5KCIZMZ8iSZWRO12Uh0hGDSDq2/brSgUBzrh4BXSNjFwzXJD9IIWIpOtdIFV0tPiMQzXU/zky+pVv5Rirpa1JHAuPc2jLV8F8KSg3K9+u84lQI5dtXMd4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Position = _t, #"Test Dates" = _t, #"Serial no." = _t, #"Test 1" = _t, #"Test 1 P/F" = _t, #"Test 2" = _t, #"Test 2 P/F" = _t, #"Test 3" = _t, #"Test 3 P/F" = _t, #"Test 80" = _t, #"Test 80 P/F" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Position", Int64.Type}, {"Test Dates", type date}, {"Serial no.", type text}, {"Test 1", type number}, {"Test 1 P/F", type text}, {"Test 2", type number}, {"Test 2 P/F", type text}, {"Test 3", type number}, {"Test 3 P/F", type text}, {"Test 80", type number}, {"Test 80 P/F", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Test 1 P/F", "Test 2 P/F", "Test 3 P/F", "Test 80 P/F"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Position", "Test Dates", "Serial no."}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Columns", "Custom", each Table.RowCount(
Table.SelectRows(#"Table (2)",(x)=>x[Position]=[Position] and x[Custom]=[Attribute]))),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Custom"})
in
    #"Removed Columns1"

Final output:

vjianbolimsft_3-1672384528062.png

Best Regards,

Jianbo 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

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @katto16 ,

 

Please check your table Oven_1212 Unpivot readings for anything missing.

Also here are two posts about this issue, you can refer to them.

Expression.Error: Evaluation resulted in a stack o... - Microsoft Power BI Community

Solved: Expression.Error: Evaluation resulted in a stack o... - Microsoft Power BI Community

Hope they can help you.

 

Best Regards,

Jianbo Li

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

v-jianboli-msft
Community Support
Community Support

Hi @katto16 ,

 

You can achieve this by using Power Query.

Please try:

First create two tables: Table remove Test P/F columns and Unpivot Test columns, Table(2) Remove Test columns and unpivot Test P/F columns.

vjianbolimsft_0-1672384232660.png

vjianbolimsft_1-1672384250138.png

Then filter Table(2) and add a custom column, here is the M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc+7DoAgDEDRf2HW0hbqY3RxdicMjiZu/n8iNUZCkAluSU5KCIZMZ8iSZWRO12Uh0hGDSDq2/brSgUBzrh4BXSNjFwzXJD9IIWIpOtdIFV0tPiMQzXU/zky+pVv5Rirpa1JHAuPc2jLV8F8KSg3K9+u84lQI5dtXMd4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Position = _t, #"Test Dates" = _t, #"Serial no." = _t, #"Test 1" = _t, #"Test 1 P/F" = _t, #"Test 2" = _t, #"Test 2 P/F" = _t, #"Test 3" = _t, #"Test 3 P/F" = _t, #"Test 80" = _t, #"Test 80 P/F" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Position", Int64.Type}, {"Test Dates", type date}, {"Serial no.", type text}, {"Test 1", type number}, {"Test 1 P/F", type text}, {"Test 2", type number}, {"Test 2 P/F", type text}, {"Test 3", type number}, {"Test 3 P/F", type text}, {"Test 80", type number}, {"Test 80 P/F", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Test 1", "Test 2", "Test 3", "Test 80"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Position", "Test Dates", "Serial no."}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] = "Fail")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each Text.Start([Attribute],
Text.Length([Attribute])-4))
in
    #"Added Custom"

Output:

vjianbolimsft_2-1672384354284.png

Then add a custom column in Table then use the custom column to filter Table, after that remove the custom column, now the Table only have the value of the "Test  " when the "Test  P/F" is "fail"

Here is the M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc+7DoAgDEDRf2HW0hbqY3RxdicMjiZu/n8iNUZCkAluSU5KCIZMZ8iSZWRO12Uh0hGDSDq2/brSgUBzrh4BXSNjFwzXJD9IIWIpOtdIFV0tPiMQzXU/zky+pVv5Rirpa1JHAuPc2jLV8F8KSg3K9+u84lQI5dtXMd4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Position = _t, #"Test Dates" = _t, #"Serial no." = _t, #"Test 1" = _t, #"Test 1 P/F" = _t, #"Test 2" = _t, #"Test 2 P/F" = _t, #"Test 3" = _t, #"Test 3 P/F" = _t, #"Test 80" = _t, #"Test 80 P/F" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Position", Int64.Type}, {"Test Dates", type date}, {"Serial no.", type text}, {"Test 1", type number}, {"Test 1 P/F", type text}, {"Test 2", type number}, {"Test 2 P/F", type text}, {"Test 3", type number}, {"Test 3 P/F", type text}, {"Test 80", type number}, {"Test 80 P/F", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Test 1 P/F", "Test 2 P/F", "Test 3 P/F", "Test 80 P/F"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Position", "Test Dates", "Serial no."}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Columns", "Custom", each Table.RowCount(
Table.SelectRows(#"Table (2)",(x)=>x[Position]=[Position] and x[Custom]=[Attribute]))),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Custom"})
in
    #"Removed Columns1"

Final output:

vjianbolimsft_3-1672384528062.png

Best Regards,

Jianbo Li

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

Hi @v-jianboli-msft Thanks for the solution. It seems to be working until this step
adding custom column in Table. My M code looks the same to you but it's returning me an error code "Expression.Error: Evaluation resulted in a stack overflow and cannot continue"

katto16_0-1673492289840.png

 #"Added Custom" = Table.AddColumn(#"Unpivoted Only Selected Columns", "Custom", each Table.RowCount(
Table.SelectRows(#"Oven_1212 Unpivot readings",(x)=>x[Oven Position]=[Oven Position] and 
x[Custom]=[Attribute])))
in
    #"Added Custom"

This is my M code.

 

katto16_1-1673492391340.png

This the Power Query adding custom column step.

 

Any idea what the problem could be?

Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.