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

Power BI - Time Intelligence "State-in-time" Chart

Hello! I am looking to create a graph that shows the status of different items (rows of data) based on the dates of different activities that are included in the columns. 

 

So, I would want on the x axis to be the month and on the y axis would be the count of instances. And it would be a stacked bar chart showing the count of items in each "Initial Work," "Pending," "Approved," and "Complete" on a given date. So for 1/1/19 I would see just a count of 3 for initial work. For 4/1/19 you would see 1 initial work, 3 pending, 5 approved, 3 complete in a stacked bar chart. 

 

I am really just looking for some direction on the best way to tackle this problem. I am assuming I will need to have measures to count on a specific date saying if complete and approved are blank, then count, etc..., but I am not sure the best way to set it up (or if it is even possible??). Thank you in advance!!

 

Also - wanted to add that I can see how you could do this in excel easily with a few countif functions and create a table based on dates and use the second table for the chart... but this is a part of a larger project where we are setting up a dashboard, so if there is a way to keep it in BI that would be preferred. 

 

Untitled picture.png

1 ACCEPTED SOLUTION

Yes, I was able to find a solution! Basically I did the following: 

 

  1. Create date master table that has all the relevant dates included.
  2. Create “Status Changes” table
    1. This is an unpivoted version of the source table - gives the “start date” for each status.
    2. Added status sort order column and use this to sort the table for non-alphabetical statuses.
    3. Calculate the Max status for each Name
    4. Calculate the last day in state based on the start date in the next state (or if it is the max status, then there is no last date)
  3. On the Date Master, create formulas to count the number of items in a certain status based on the date beginning and ending range.

 Let me know if that helps or if you need any clarification!

View solution in original post

6 REPLIES 6
v-frfei-msft
Community Support
Community Support

Hi @swiley9 ,

 

Select the Name column and unpivot Others columns as below.

1.PNG

M code for your reference.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTLUN9Q3MjC0RGcaI5gmEGasTrSSE1jAiJAOU4QOZ3RlRhgG6yiBVboQoxLFNa7oyoyxakZyjRu6HHamGUKHO6rBeFR6oMrhUemJxUwTrCq90MIJgkAy3ugeRjYOrMIHZ+jAVPjiiGmECj8coY8jTmIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, #"Initaial Work" = _t, Pending = _t, Approved = _t, Complete = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Initaial Work", type date}, {"Pending", type date}, {"Approved", type date}, {"Complete", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Name"}, "Attribute", "Value")
in
    #"Unpivoted Other Columns"

 

Then we can create starcked column chart after applying the steps in power query.

Capture.PNG

 

For more details, please check the pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thanks! The problem is that both of these options only show me the date that things change, and not the status on a given date! Still looking for a solution to this, didn't realize it would be such a complicated question!

@swiley9 

Were you able to find a solution?

Yes, I was able to find a solution! Basically I did the following: 

 

  1. Create date master table that has all the relevant dates included.
  2. Create “Status Changes” table
    1. This is an unpivoted version of the source table - gives the “start date” for each status.
    2. Added status sort order column and use this to sort the table for non-alphabetical statuses.
    3. Calculate the Max status for each Name
    4. Calculate the last day in state based on the start date in the next state (or if it is the max status, then there is no last date)
  3. On the Date Master, create formulas to count the number of items in a certain status based on the date beginning and ending range.

 Let me know if that helps or if you need any clarification!

Thank you very much, kudos to you!

 

Any chance of sharing a PBIX?

Anonymous
Not applicable

You will have to unpivot the columns and convert them to row. e..g https://www.newtechdojo.com/unpivot-columns-in-power-bi/

 

Then use stacked column chart: https://docs.microsoft.com/en-us/power-bi/visuals/power-bi-visualization-combo-chart

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.