Forum Discussion
perform logic on variable number of columns
Hi,
I have a table of projects that have requirements, and I'm trying to determine if all of the requirements have been met for each project. If any requirement has not been met, the project itself has not met its requirements. Regardless of the amount of requirements, there are columns for three. If a project only has one, then the other two are null and are ignored. I'm finding it difficult to only evaluate the requirements columns that have values.
The data looks like this
| project | req_1 | req_1_met | req_2 | req_2_met | req_3 | req_3_met |
| project_1 | gleam the cube | TRUE | do the right thing | TRUE | ghosts busted | TRUE |
| project_2 | come to america | TRUE | run the blade | TRUE | ||
| project_3 | dance flashed | TRUE | groove krushed | FALSE | foot loose | TRUE |
I don't know how to do this without something like a `do while` loop. Also wasn't sure if this should be done in power query.
Thanks!
edit: wow that table is ugly. Should look like this
What you are looking for is the Unpivot option - usually needed to bring Excel data into a format that is usable by Power BI.
after that it will be easy to achieve your objective in Power BI.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TY69DsIwDIRfxcrcBXgCBpiY+JmqCOXHTQppjRKH5yeNgHSwbH0n313fi1ekBxq+b0QnXEA1AXsEkzUWcD3fDmVZqjCOznO5xtk1zXlKnEDnxGh/WHbNeFugoQmBCdSEcTSqfcc8V2sdlF0FQp21y26poWaDMASVfIsqDSLRG+EZ85cf96fLIgxEDIEo/Z2l/AA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [project = _t, req_1 = _t, req_1_met = _t, req_2 = _t, req_2_met = _t, req_3 = _t, req_3_met = _t]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"project"}, "Attribute", "Value"), #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Attribute.1", "req #", "status"}), #"Replaced Value" = Table.ReplaceValue(#"Split Column by Delimiter",null,"req",Replacer.ReplaceValue,{"status"}), #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Attribute.1"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[status]), "status", "Value") in #"Pivoted Column"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.
5 Replies
- Irwan
Super User
hello genehiggins
what is the desired outcome from the above sample data?
is it counting of project with TRUE value in all requirements?
Thank you. - lbendlin
Super User
What you are looking for is the Unpivot option - usually needed to bring Excel data into a format that is usable by Power BI.
after that it will be easy to achieve your objective in Power BI.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TY69DsIwDIRfxcrcBXgCBpiY+JmqCOXHTQppjRKH5yeNgHSwbH0n313fi1ekBxq+b0QnXEA1AXsEkzUWcD3fDmVZqjCOznO5xtk1zXlKnEDnxGh/WHbNeFugoQmBCdSEcTSqfcc8V2sdlF0FQp21y26poWaDMASVfIsqDSLRG+EZ85cf96fLIgxEDIEo/Z2l/AA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [project = _t, req_1 = _t, req_1_met = _t, req_2 = _t, req_2_met = _t, req_3 = _t, req_3_met = _t]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"project"}, "Attribute", "Value"), #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Attribute.1", "req #", "status"}), #"Replaced Value" = Table.ReplaceValue(#"Split Column by Delimiter",null,"req",Replacer.ReplaceValue,{"status"}), #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Attribute.1"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[status]), "status", "Value") in #"Pivoted Column"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.
- V-yubandi-msft
Community Support
Hi genehiggins ,
Thank you for engaging with the Microsoft Fabric Community. lbendlin response matches your requirement. Please review it when you have a chance and let us know if you need any changes.
Thank you.
- V-yubandi-msft
Community Support
Hi genehiggins ,
Has your issue been completely resolved, or is there anything else I can assist you with. Your feedback matters to us. If you have more questions or need further support, feel free to let us know.
- V-yubandi-msft
Community Support
Hello genehiggins ,
I wanted to follow up and see if your issue has been resolved. If you're still experiencing any challenges or need further assistance, please feel free to reach out.
Thank you.