Customize and managing tables in Power Query - powerbi

I'm trying to predict (based on simple average) energy consumption untill the end of the month.
I have a table with accumulated energy consumption of my plant until yesterday.
Data Structure in Power Query
'Energy Meter Code', 'Date', 'Hour of the Day', 'Day of the week = Dia Semana', and 'Consumption (MWh)' are the most important columns in this table.
I understand my next step is to:
Create a table with the rest of the days of current month
Calculate average consumption based on different parameters (day of the week, hour of the day, etc) for each hour of the following days
Merge two tables and it's done
However, I don't know how to customize tables in Power Query (syntax problem).
Is there any simple way where I may create dynamic table considering the missing days till the end of the month? Or even better, considering how many hours do we have
Thanks in advance for sharing your experience

Related

Power Pivot - Is it possible to setup a date relationship to a table with a FROM and TO date

I have been searching the internet for support with this but cannot find anything that fits the bill. I'm not sure if what I want to do is possible, so if someone can please help
I have a table of employees which contains a column 'FTE' (Full Time Equivalent) with an effective date from and effective date to. The FTE changes based on the dates from and to.
I want to create a data model that allows me to work out FTE daily and aggregate using Pivot into Weekly/Monthly/Yearly FTE
If an employee is full-time, they will show as 1.0 FTE with the dates that reflect the time they were 1.0. So example, 01/04/2022 to 31/07/2022 - this will show as 1.0 and 1 row in my data. I want to be able to calculate FTE on a monthly basis by multiplying the FTE by the number of days in the month, so potentially 31 FTE days
I'm struggling to understand how to create a relationship between the employee table with the FROM and TO dates on my date table.
A workaround that would work but is too inefficient is to create a full list of dates for each employee in PowerQuery first as this will generate 2+ million records

Trying to make a date slicer which includes both date and time

I have a table of many datetime datapointname value triplets from process probe sensors.
I want to have a slicer which I can use to pick from time1 on day 1 to time2 on day 2
So my approach has been to have three slicers [Time Start] [Date Slicer] [Time End]. I have the data table and two time tables in 30 minute intervals so I have been able to create measures and display cards to show on the report the start and stop datetime combo.
I try to combine all this into a new table using DAX which filters the data table using the measures that I have but have not had any success.
Does anyone how how to set up a slicer or set of slicers so I can filter my report (for example), from 2022-Jun-15 at 4:30 PM to 2022-Jun-18 at 10:00 AM?
I am just learning about DAX. I have spent a few hours at this with no sucess.
Thanks
That's probably not a good idea from a modelling perspective. Data modelling best practice suggests that your Date (where 1 row = 1 day) and Time (where 1 row = 1 second or 1 minute, as necessary) dimension tables should be separate.
I would therefore recommend you setup your model in such a way that you have these two dimensions as two separate tables. You should then just be able to have two slicers - one from each table - to do what you need.
Note: this of course means that your fact tables will need to have separate columns (one for the date and one for the time) to join to your Date and Time dimension tables.

Rolling Average Prediciton for Future 30 Days in DAX

I am working on a forecasting graph that will be pulling in data from SQL through power query. The graph will have slicers and filters available to the user to analyze different populations. I am currently being asked to provide a rolling average for each day of the next month but will update daily as more data becomes available. I need 30 days of rolling average that occur after the current date. Using the prior days rolling average calculation. This has to be completed in dax to allow the filters and slicers to work appropriately. The rolling average looks 14 days back.
Any ideas on how to best proceed would be greatly appreciated.
Below is a table of data to show how this looks in excel:

Cumulative/Rolling Sum Blank Dates

I'm currently working on inventory reconciliation, and I've struggling to fill all days of the calendar with the cumulative sum of product we're currently storing:
Inventory level ($). = CALCULATE(SUM(ledger[cost]),FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(ledger[Document Date])))
As you guys might notice it has at least 90% of all dates filled, however if we look closely to the graph, we can appreaciate March 5th of 2016 is missing just due to the fact there was no transaction during that day resulting on a blank value. However I'm trying to accomplish retrieving the previous day balance for those days with no transactions. e.g: for March 5th should have $17,038,462.32 (balance for the previous day March 4th).
I'm trying to work on another clause into the measure with functions such as EARLIER or LASTDATE, however I haven't been succesful.
Any insight or solutions works well thank you. Have a nice day.
You are using a wrong date field in your measure. Change it to the field from the Date table:
Inventory level. =
CALCULATE(
SUM(ledger[cost]),
FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(DimDate[Date])))

Excluding Weekends in Power Bi when calculating the difference in dates and times

I've been doing a lot of research on this question over the past few days, but none of the articles I've researched have been able to do. I'm trying to find the difference between two dates in Power BI that excludes weekends, but it also needs to calculate the differences in times as well. All of the articles I've seen have been able to find the difference in the dates themselves, but for my specific problem, the times are important.
For example,
I'm trying to find the difference between Pickup Date/Time and Created Date/Time. The data I am looking at is to find all the shipments that were entered into the system two business days in advance of the pickup date, and those shipments need to be entered in before noon that day.
I've created a Date table that has all dates between 2018-2020 that show whether it's a weekend or a weekday, but I haven't been able to figure out how to basically do Pickup From - Created From and filter out the weekends.
Any help with this would be greatly appreciated.
My data is below that i'm trying to use.
Supplier Lead Times Table with Created/Date Time and Pickup From/Date Time
Lead Time Days
The Lead Time days currently is just ('Supplier Lead Times' [Pickup From Date/Time] - 'Supplier Lead Times'[Created Date/Time]).
Even if I could use the DATEDIFF HOURS function for this, that would work, i'm just having trouble filtering out the weekend days. I have a calendar table that has all the weekdays/weekends
Calendar Week Table
As far as I checked, your "Create Date" and "Pickup Date" fields are always weekdays. Therefore, if we calculate the total difference than put 24 hour back for each weekend, that would work. Try to create a quick measure column like below and apply it to your table:
Difference =
var weekends =
SUMX(
SELECTCOLUMNS(
CALENDAR(min('MyTable'[CreatedDate]), min('MyTable'[PickUpDate])),
"Date", min('MyTable'[CreatedDate]),
"BDay", IF(WEEKDAY([Date],3) >= 5, 1, 0)
),
[BDay]
)
return DATEDIFF(min('MyTable'[CreatedDate]), min('MyTable'[PickUpDate]), HOUR) - weekends*24