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
genehiggins
Frequent Visitor

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

projectreq_1req_1_metreq_2req_2_metreq_3req_3_met
project_1gleam the cubeTRUEdo the right thingTRUEghosts bustedTRUE
project_2come to americaTRUErun the bladeTRUE  
project_3dance flashedTRUEgroove krushedFALSEfoot looseTRUE

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

genehiggins_0-1753377224901.png

 

3 REPLIES 3
V-yubandi-msft
Community Support
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.

lbendlin
Super User
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.

 

lbendlin_0-1753398186441.png

 

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.

 

 

 

Irwan
Super User
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.

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.