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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Federiko23
New Member

How to transform this excel?

Hi! I'm starting with PowerBI and have a question about an excel I want to transform and visualize. The information comes in this way:

 

Requirement |  Status from  |  Status

a  |   1/1/2017  | Open

a  |  1/3/2017  | In Process

a  | 1/9/2017 | Closed

b  | 3/2/2017 | Open

c  | 2/1/2017 | Open

b  | 4/1/2017  | In Process

....

 

What I'd like to end up are a table where I can indicate the number of days each requirement was in specific status, so in excel what I can do is sort by requirement and then by status from, and then create a new column that checks the requirement from the below's row, and if it is the same it just takes below's "status from" and deducts the one from the current row, if the below's requiremen is not the same as the current row then it uses the current date to deduct 

 

Result should be something like:

 

requirement |  Status  | amount of days

a  |  open  |  2

a  | In Process | 6

...

 

I can get to that manipulating the excel before importing it in powerbi, but is there any way to do it directly in powerbi so I skip that step every time I refresh the info?

 

Thank you!

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

 

Write a calculated column formula in the PowerPivot

 

=IF(ISBLANK(CALCULATE(MIN(Data[Status From]),FILTER(data,Data[Requirement]=EARLIER(Data[Requirement])&&Data[Status From]>EARLIER(Data[Status From])))),TODAY(),CALCULATE(MIN(Data[Status From]),FILTER(data,Data[Requirement]=EARLIER(Data[Requirement])&&Data[Status From]>EARLIER(Data[Status From]))))-Data[Status From]

 

Untitled.png


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

View solution in original post

Power Query solution:

 

let
    Source = Table1,
    #"Sorted Rows" = Table.Sort(Source,{{"Requirement", Order.Ascending}, {"Status from", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1),
    #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 1, 1),
    #"Merged Queries" = Table.NestedJoin(#"Added Index1",{"Index.1"},#"Added Index",{"Index"},"Next",JoinKind.LeftOuter),
    #"Expanded Next" = Table.ExpandTableColumn(#"Merged Queries", "Next", {"Requirement", "Status from"}, {"Next.Requirement", "Next.Status from"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Next", "amount of days", each Duration.TotalDays((if [Next.Requirement] <> [Requirement] then DateTime.Date(DateTime.FixedLocalNow()) else [Next.Status from]) - [Status from]), Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index", "Index.1", "Next.Requirement", "Next.Status from"})
in
    #"Removed Columns"

 

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

 

Write a calculated column formula in the PowerPivot

 

=IF(ISBLANK(CALCULATE(MIN(Data[Status From]),FILTER(data,Data[Requirement]=EARLIER(Data[Requirement])&&Data[Status From]>EARLIER(Data[Status From])))),TODAY(),CALCULATE(MIN(Data[Status From]),FILTER(data,Data[Requirement]=EARLIER(Data[Requirement])&&Data[Status From]>EARLIER(Data[Status From]))))-Data[Status From]

 

Untitled.png


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

Power Query solution:

 

let
    Source = Table1,
    #"Sorted Rows" = Table.Sort(Source,{{"Requirement", Order.Ascending}, {"Status from", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1),
    #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 1, 1),
    #"Merged Queries" = Table.NestedJoin(#"Added Index1",{"Index.1"},#"Added Index",{"Index"},"Next",JoinKind.LeftOuter),
    #"Expanded Next" = Table.ExpandTableColumn(#"Merged Queries", "Next", {"Requirement", "Status from"}, {"Next.Requirement", "Next.Status from"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Next", "amount of days", each Duration.TotalDays((if [Next.Requirement] <> [Requirement] then DateTime.Date(DateTime.FixedLocalNow()) else [Next.Status from]) - [Status from]), Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index", "Index.1", "Next.Requirement", "Next.Status from"})
in
    #"Removed Columns"

 

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors
Top Kudoed Authors