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
leeedney
New Member

Finding values in a row in PowerBI

Hi everyone,

 

I have a table in PowerBI in a format similar to:

 

Project ID       Milestone1       Milestone2       Milestone3       Milestone4      Milestone5

1                     01/04/17          01/05/17          02/07/17          09/09/17          01/12/18

2                     17/04/17          11/06/17          02/08/17          09/10/17          26/12/18 

...

 

What I want to do is create a new column that works out which stage each project is at, by comparing it to a static measure. In Excel I'd do an INDEX MATCH (less than) for each row that returned the top row of data. Is it possible to do that when you're actually asking PowerBI to return the column name?

 

Open to any suggestions.

 

Thanks,

-Lee

 

The excel code would be:

=INDEX($A$1:$F$1,1,MATCH(LookupDate,$A2:$F2,1))
1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

I created a table in Excel according to your example and created the following code in the Query Editor.

Edit: I also created parameter StaticMeasure with type date.

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\Marcel\Documents\Forum bijdragen\Power BI Community\Finding values in a row in Power BI.xlsx"), null, true),
    Projects_Table = Source{[Item="Projects",Kind="Table"]}[Data],
    Typed = Table.TransformColumnTypes(Projects_Table,{{"Project ID", Int64.Type}, {"Milestone1", type date}, {"Milestone2", type date}, {"Milestone3", type date}, {"Milestone4", type date}, {"Milestone5", type date}}),
    #"Added Custom" = Table.AddColumn(Typed, "Stage", each List.Union({{"No Milestone yet"}, List.Skip(Record.FieldNames(_))}){List.Count(List.FirstN(List.Skip(Record.FieldValues(_)),each _ <= StaticMeasure))})
in
    #"Added Custom"

 

Specializing in Power Query Formula Language (M)

View solution in original post

1 REPLY 1
MarcelBeug
Community Champion
Community Champion

I created a table in Excel according to your example and created the following code in the Query Editor.

Edit: I also created parameter StaticMeasure with type date.

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\Marcel\Documents\Forum bijdragen\Power BI Community\Finding values in a row in Power BI.xlsx"), null, true),
    Projects_Table = Source{[Item="Projects",Kind="Table"]}[Data],
    Typed = Table.TransformColumnTypes(Projects_Table,{{"Project ID", Int64.Type}, {"Milestone1", type date}, {"Milestone2", type date}, {"Milestone3", type date}, {"Milestone4", type date}, {"Milestone5", type date}}),
    #"Added Custom" = Table.AddColumn(Typed, "Stage", each List.Union({{"No Milestone yet"}, List.Skip(Record.FieldNames(_))}){List.Count(List.FirstN(List.Skip(Record.FieldValues(_)),each _ <= StaticMeasure))})
in
    #"Added Custom"

 

Specializing in Power Query Formula Language (M)

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.