Converting decimal time to hours to plot a 24-hour timeline chart in power bi - powerbi

hope you're doing well.
I'm a newbie to PowerBI and I'd want to convert the decimal time/date column values into hours of the time to plot the info over a 24-hour timeline. I was able to achieve this in tableau and as it automatically detects the hours and can easily be able to plot the info. I was a bit close in achieving this in powerBI as I converted the date/time column to time and tried plotting but there's huge noise and looks more cluttered as it took every change in seconds/minutes (the bottom snippet). I've attached the snippets for reference, can anyone pls try to help me on this ?

In Power BI it's recommended to split the DateTime column into separate Date and Time columns. This is both for performance reasons. Over a year a DateTime column with 1sec granularity can have 30M different values, which is much more data than storing one column with 365 values, and one with 86,400 values. And so that your Date column can link to a Date Dimension to provide other DateTime hierarchy attributes, like FiscalQuarter, DayOfWeek, etc.
In Power Query select the DateTime column and go to --> Add Column --> Time -- > Time Only. Then change the data type of the DateTime column to Date.
This also solves your reporting problem as you can simply put the Time column on the X axis.
If you want a custom format string for the time you can add a calculated column in Power Query like
= Table.AddColumn(#"Changed Type1", "TimeDesc", each DateTime.ToText(#date(2020,1,1)&[Time], [Format="h tt"]))
And configure the new column with a "Sort by Column" of Time.

Related

Show all data for month to date

In Power BI, I am creating a grid to show specific data in a time period. I want the grid to update everyday to show the data corresponding month to date. I want my data to represent 9/7 - 10/7 and tomorrow I want it to update to show 9/8-10/8. Essentially I want a measure in DAX to display all data from month to date.
You can do this from relative date filter in the right side tabs,
Select visualization and their is filter for date,
try with above method.

Create a pivot table in Power BI with dates instead of aggregate values?

I have a table of companies with descriptive data about where we are in the sales stage with the company, and the date we entered that specific stage. As can be seen below, the stages are rows in a Process Step column
My objective is to pivot this column so each Process Step is a column, with a date below it, as shown in excel:
I tried to edit the query and pivot the column upon loading it, but for the "aggregate value" column, no matter which column I use as the values column, it results in some form of error
My advice would be not to pivot the table in the query and use measures to get dates that you want. The benefit of not doing so is that you are able to perform all sorts of other analytics. For instance, Sankey chart would be hard to do properly with pivoted table.
To get the pivot table you are showing from Excel, it's as simple as using matrix visual in Power BI and putting Client code in rows and Process Step in Columns, then Effective date in values.
If you need to perform calculations between stages, it's also not too difficult. For instance, you can create a meausure that shows only dates at certain stages, another measure for another stage, and so on. For example:
Date uploaded = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Upload"))
Date exported = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Export"))
Time upload to export = DATEDIFF([Date uploaded], [Date exported], DAY)
These measures will work in the context of client and assuming there is only one date for the upload step (but no Process step in rows or columns). If another scenario is needed, perhaps a different approach could be taken.
Please let me know if that solves your problem.

Power BI DAX Dynamic Calendar

I am trying to create a Dynamic Table in Power BI.
I have my set of data, and basically I want the calendar to pick up the minimum date and the maximum date from my table, but only if the maximum date is not the month of today. If the maximum date is the month of today, then it should ignore it and the calendar should be created with the max date of the previous month.
I started the formula, but can't seem to continue it. Any ideas?
Calendar_= CALENDAR(MIN('Table1'[Date]),IF(MONTH(MAX('Table1'[Date]))=MONTH(TODAY()),date(YEAR(MAX('Table1'[Date])),.....
See if this post helps: https://community.powerbi.com/t5/Desktop/Dynamic-table-or-on-fly-table-generation-via-DAX/m-p/434397#M200275. If not, I would simplify by creating some additional calculated columns or measures and then reference those instead of one nice big formula

PowerBI measure calculates average incorrectly - why?

To preface this, I'm fairly experienced in Excel and VBA but new to PowerBI and more than a bit confused.
I have a flat table with a [creationdate]-, [Prio] (Priority (1,2,3)) and a calculated [Days Open] column, among many irrelevant others. I need to create a chart that displays the average days a case was open by priority of the case.
To display the average "days required" per (opening-) month for the past 18 months, I created the following measure:
Prio 1 = CALCULATE(AVERAGE('SourceName'[Days Open]),'SourceName'[Prio]=1)
Then I used that as a value, and used the [creationdate] as the x-axis. (Later I changed the x-axis to a new date table linked to [creationdate] without it making a difference.) To display this as monthly averages, I used the hierarchy limited to years and months, and went down one level in the chart.
Something seemed off so I checked first in Excel, then in the data source in PowerBI and yep: The averages in the PowerBI chart are complete bullshit.
Where did I go wrong? I assume it has something to do with the date hierarchy... So I created a date table as recommended (which....why?!) and linked it. That didn't make a difference.
Meanwhile in the data panel if I filter by the date column and calculate the average with the filtered selection of numbers externally, everything works as expected, so its not like there's a date formatting issue.
Do I have to create a calculated column with something akin to
DATE(YEAR([DateColumn]),MONTH([DateColumn]),1)
, then use that as the x-axis without the hierarchy, and hope nobody cares about the day in the label? Or is there something wrong with the measure used? I'm completely lost.

How can I get the number of days by month from a slicer in Power BI?

I just want to select a range of days in a slicer and show in a table the number of days for each month/period (month-year).
I used DAX to create a table with the information I need and I don't have problems with the periods (first column), it changes dinamically, the problem is the column "Days" (second column) because it's always showing the total number of days for each month.
Here my DAX code
SelectedPeriods = GROUPBY(DimDate;DimDate[Period];"Days";COUNTX(CURRENTGROUP();DimDate[DateKey]))
Here the result
What I expect is:
2 for april, 31 for may, 1 for june
This is an issue with execution order.
SelectedPeriods = GROUPBY(DimDate;DimDate[Period];"Days";COUNTX(CURRENTGROUP();DimDate[DateKey]))
Generates a calculated table. These are calculated when the data model is refreshed and stored in it. They are not refreshed each time a connected dimension is changed within a dashboard.
In your case, while changing date filters may hide rows from this table the number of days remains fixed at the number calculated initially when there was no filter context on the data i.e. counting all days in the month.
If you want the result to change then you need to use a measure instead of a calculated table. Measures react to the current filter context within the report and so will adjust their output each time a slicer is changed.
The needed measure will depend on your model but might be something as simple as:
CountOfDays := CountRows(DimDate)