I have a Power BI heat map that measures the uptime of equipment for the current hour and each of the 8 hours prior:
The problem lies in the fact that a given hour may not always have records; in the above example, the machine was running from 4 AM to 6 AM non-stop and did not have any records for the 5 AM hour to indicate that it had been up and running that entire hour. The -3 hour should be showing 100% but it is incorrectly showing 0%.
This visualization has a separate measure for each hour, calculating the uptime for each hour. For example, Hour -3 has a calculation as follows:
-3 = IF(ISBLANK(CALCULATE(COUNTROWS(UptimeCombined), FILTER(UptimeCombined, UptimeCombined[Hours_Offset] = 3))) = TRUE,
(CALCULATE('UptimeCombined'[Uptime %], FILTER(UptimeCombined, UptimeCombined[Hours_Offset] > 3 && UptimeCombined[ShiftDateTime] = MAX(UptimeCombined[ShiftDateTime])))),
(CALCULATE('UptimeCombined'[Uptime %], FILTER('UptimeCombined', 'UptimeCombined'[Hours_Offset] = 3))))
If the row count comes back BLANK, then I need to look BACKWARD in time (max record where Hour_Offset > 3) and find the status (either "RN" or "DN") of whatever the last record was and display that uptime value for that hour (100% or 0%, respectively) but I can't get that part of the measure to work properly; the -3 hour should show 100% because the latest record before then had status of "RN" (in the -4 hour). Here is what the data looks like:
What is the correct DAX I need in Line 2 of this measure to set the uptime to either 100% or 0%, based on the latest record from before that hour?
I ended up filling in the data gaps in the source view on the SQL Server side before the data ever hits Power BI... much simpler that way than trying to mess with complex calculations and measures.
Related
Please, I created my table using hour time partition. Please, I would like would like to fetch data that was stored in my table in the last X minutes, eg last 5 minutes.
I tried using this command
SELECT *
FROM mydataset.mytable
FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);
But, it returns a lot more rows than what is expected. I typically store 500 rows every 2 minutes, but this query is returning more than 30000 rows
As #Samuel mentioned in the comment, below example query can be considered to fetch data for a specific time period in BigQuery.
Select * from `dataset.table`
WHERE col_timestamp < TIMESTAMP_SUB(CURRENT_TIMESTAMP(),
INTERVAL 5 MINUTE)
Posting the answer as community wiki for the benefit of the community that might encounter this use case in the future.
Feel free to edit this answer for additional information.
Here is the sandbox link: https://codesandbox.io/s/chartjs-plugin-zoom-touch-scroll-y-forked-6q5li4?file=/src/components/ChartLine.vue
I am trying to build a chart out of some time-series data that I have.
I have a picker to select the scale: hour, day, week, and month, and the data can span up to 4 months. I start on the hour scale, but a visual problem I have is that I initially want the chart to focus on the last n hours/days/weeks instead of the current behavior where the chart shows the entire x-axis so the hour unit doesn't really make sense without tooltips.
How can I set limits using a UNIX timestamp of the min and max, and have the chart initially focus on the last n units? Like the last 4 hours or 4 days or 4 weeks or 4 months?
I have an explore like the following -
Timestamp Rate Count
July 1 $2.00 15
July 2 $2.00 12
July 3 $3.00 20
July 4 $3.00 25
July 5 $2.00 10
I want to get the below results -
Rate Number of days Count
$2.00 3 37
$3.00 2 45
How can I calculate the Number of days column in the the table calculation? I don't want the timestamp to be included in the final table.
First of all— is rate a dimension? If so, and you have LookML access, you could create a "Count Days" measure that's just a simple count, and then return Rate, Count Days, and Count. That would be really simple.
If you can't do that, this hard to do with just a table calculation, since what you're asking for is to change the grouping of the data. Generally, that's something that's only possible in SQL or LookML, where you can actually alter the grouping and aggregation of the data.
With Table Calculations, you can make operations on the data that's been returned by the query, but you can't change the grouping or aggregation of it— So the issue becomes that it's quite difficult to take 3 rows and then use a table calculation to represent those as 1 row.
I'd recommend taking this to the LookML or SQL if you have developer access or can ask someone who does. If you can't do that, then I'd suggest you look at this thread: https://discourse.looker.com/t/creating-a-window-function-inside-a-table-calculation-custom-measure/16973 which explains how to do these kinds of functions in table calculations. It's a bit complex, though.
Once you've done the calculation, you'd want to use the Hide No's from Visualization feature to remove the rows you aren't interested in.
I need to find one way or another the following formula in Power BI:
Total Hours of Use of a Machine = Hours Function * Range of Functioning
where Hours Function is the hours of use of a certain machine. Take it at a cost that for each machine is a constant and Range of Functioning is the difference between the final date of the evaluation and the initial date, measured in hours.
For example, I want to measure the Total Hour Use of a Machine in between 15/10/2019 and 14/20/2019. So the math is the following:
Assume: 2 machines
Hours Function machine A: 6
Hours Function machine B: 9
Range of Functioning = 15/10/2019 - 14/10/2019 = 24 hours
The output:
Total Hours of Use of a Machine A: 144
Total Hours of Use of a Machine B: 216
I need to do that in Power BI in a way that any user moving a slicer of date, refresh the Total Hours of Use of a Machine.
I don't find any way that I can get the difference between the final date of the evaluation and the initial date and put in DAX or a new column.
You have to use measures if you want to recalculate the value when you change the date with a slicer.
The first step is to be sure to be able to calculate the number of day selected by your slicer.
It seems to be easy but if you use the function FirstDate on your calendar table directly integrated in PowerBI.
You'll never have what you expect.
The tricks here to get this number of day is to calculate the number of rows in your calendar table with the function countrows.
When you have this number day you just have to multiply this by 24 ( hours) and by the sum of your "Hours Function machine".( 6 for A 9 for B in your example )
( It's important to use the sum or another aggregate function like average because if you have multiple value the measure fall in error because it need only one value to multiply).
The dax formula looks like :
= COUNTROWS(('Calendar')) * Sum(Machine[Hours function])
You can then display this measure filtered by the Machine Name and a date slicer(based on your calendar table).
I have entries that are uniquely identified by a variety of fields and that I pull in from Excel. Entries relate to the daily amount of work done, and people working on a specific area of a plant. Each entry has a work done field (measurement of the work done on that area), and a manpower count. The productivity per area is calculated by work done divided by manpower.
Date Area Work Done Manpower Productivity
2017/02/01 Pipe 50 25 2
2017/02/01 Valve 22 2 11
2017/02/01 Machine 54 2 22
I want to display the work done and manpower as bars in power BI, and the average productivity per day as a line. The problem is that the real productivity for the day (total work done divided by total manpower) is not the average of the individual productivity per area. Thus, I want to be able to create a line that total work done and manpower per day, and divides them to get the productivity, then only displays the productivity.
How can I do this in power BI?