Filter values by hours in Power BI - filter

I have a date table:
I need to filter this by hours. last 4h 12h 24h etc.
Relative date only gives me days-weeks and so on.

Simplest work-around could be to create a binary FLAG in the back-end to identify record created in the last 4h.
Then, define a slicer in the front-end (visible or hidden) to visualize only those records relevant for you.

Got this working by creating 4 new custom columns with code:
DateTime.IsInPreviousNHours([LastTransactionDate],4)
Which gives me values if TRUE or FALSE and can filter by turning off FALSE values.

Related

Tableau - Fixed calculated field depending on date filter

I'm new to Tableau. I am trying to make an inventory report which tells the user how much of certain product he/she should buy in advance.
Depending on the amount of days selected on the filter, the difference in days of the complete period should be calculated. For example: If the filtered dates are from 1/03/2021 to 09/03/2021, the result should be equal to 9. The formula I used is the following: date_difference = DATEDIFF("day",MIN(DATE([Fecha])), MAX(DATE([Fecha]))) + 1
The problem comes when I try to use the value given by such date filter. My next calculation should be:
calc = Quantity Inventory / (Units sold / date_difference). Both Quantity Inventory and Units sold are calculated fields in which I have no problem. However, instead of having a fixed value of 9, date_difference changes as shown in the image, giving me incorrect results for the desired calculation.
How can I make sure that the calculated field date_difference has the value of 9 on all rows?. Actually, if I add date_difference field by itself in a different Page it does show the proper value. The problem occurs when calculating calc and trying to add it to the table.
Note: Remember that the value of date_difference will change, depending on the range of time selected on the date filter
Thanks a lot in advance.
Step-1 Use this calculation for date_difference instead
DATEDIFF('day', {min(DATE([Fecha]))}, {max(DATE([Fecha]))}) +1
Step-2 Add Fecha filter to context, by right clicking it in filters shelf.
This will solve your problem. See the GIF

Data Studio Table Chart is not sorting correctly

I have a working chart of podcast episodes by download count in a query. That query is used to create a table chart in Data Studio. The file name formats are as follows: 2020/889-Jan-16-2020-DMP.mp3
Well Episode 1000 isn't showing at the top now in the sorting order. Because it thinks 1000 is less than 999. See table below:
2020/999-Jun-24-2020-DMP.mp3
2020/998-Jun-23-2020-DMP.mp3
2020/997-Jun-22-2020-DMP.mp3
2020/996-Jun-21-2020-DMP.mp3
2020/995-Jun-18-2020-DMP.mp3
2020/994-Jun-17-2020-DMP.mp3
2020/993-Jun-16-2020-DMP.mp3
continuing ...
2020/886-Jan-13-2019-DMP.mp3
2020/885-Jan-12-2019-DMP.mp3
2020/884-Jan-9-2019-DMP.mp3
2020/883-Jan-8-2019-DMP.mp3
2020/882-Jan-7-2019-DMP.mp3
2020/881-Jan-6-2019-DMP.mp3
2020/880-Jan-5-2019-DMP.mp3
2020/879-Jan-2-2019-DMP.mp3
2020/1001-Jun-30-2020-DMP.mp3 <-------Should be at the top of the table
2020/1000-Jun-29-2020-DMP.mp3 <-------Should be at the top of the table
2019/878-Dec-19-2019-DMP.mp3
2019/877-Dec-18-2019-DMP.mp3
2019/876-Dec-17-2019-DMP.mp3
Let me know if that makes sense...
1) REGEXP_EXTRACT
It can be achieved by adding the REGEXP_EXTRACT Calculated Field below as the Sort field and setting the order to Descending (The RegEx extracts the respective number component, for example 1001):
AVG(CAST(REGEXP_EXTRACT(Field, "^\\d+/(\\d+)-") AS NUMBER ) )
Google Data Studio Report and a GIF to elaborate:
2) Troubleshooting Calculated Fields (Invalid Formula)
Adding a section on general troubleshooting for Calculated Fields based on an Earlier Post on the Google Data Studio Forum:
Field Editing: Have a look at whether Field Editing is Enabled (Although it shouldn't affect creating Data Source Calculated fields);
Refresh: Refresh the Data Source Fields as well as a Fields in the Report;
Page Reload: Shortcut - F5;
Hard Page Reload: Shortcut - Ctrl + F5;
Chart-level Calculated Field: Double check whether using a Chart-level Calculated Field instead of a Data Source-level Calculated Field, resolves the issue.
I found that doing this worked too - sort date granularity by Year Week
Sort date granularity by Year Week

Sorting time stamp values that get constantly updated via google forms

I have a google sheet that gets filled via a google form.
Time stamps are created every time a bar code (work order number) is scanned.
The work order number is in the first column.
The 4 unique time stamp fields below are populated in the 2nd column from the google form.
Setup start
Setup finish
Production start
Production finish
The time stamp is created in the 3rd column.
I am trying to do conditional formatting
where the total setup time and production time are calculated but they are tied to their respective work order number.
time stamp functionality
The difficulty is that the timestamp values all fall into one vertical column.
I don't want a mix up of timestamp values with different work order numbers.
The work order numbers along with the 4 unique time stamp values may be input at various times so the formula can't be order specific.
Is there a way to do this? Thanks!
Below is an example link of the spreadsheet I have:
https://drive.google.com/open?id=1YA86jGq_jMsx-wKe19TnZZyf9F4aW6_kUIbrz8hkLJI
Make a pivot table of the data from the form, then use simple formulas adjacent to the new pivot to get the results you are trying to get. Example Image

Daily unique count, weekly unique count in the same Timelion chart

I want to visualize the unique count for a field aggregated daily and weekly per day in the same sheet. But timelion aggregation affects the entire sheet instead of just a single chart.
The expression I am using to get the daily unique count is
.es(metric='cardinality:userId').bars().title('Unique users over time')
If I change the bucket range on the right to 1d, I get the correct chart. How do I create the weekly aggregation?
There is a possibility to specify the interval used for timelion expressions by specifying interval as 1d or respectively 1w in the es() function. For details, please see the docs here.
In your case this should work with the following expression:
.es(metric='cardinality:userId',interval=1w).bars().title('Unique users per week')
Be aware of the comment inside the docs, stating that this should not be used in favor of working with the interval picker. But probably this is a use case where it is okay to do it like this...

Get first and last entry given a timespan

I am using Kibana to log actions performed by the users of my web interface.
I would like to create a visualisation that does the following:
For each of my users (I have a field for that in my Elastic entries)
Display the first and last entry datetime
Maybe should I make two visualisations, on for first, one for last, as I don't know if it possible to do it on one single Visual.
Thanks in advance
Okay, I found the answer, in the case of a Data Table visualization, I added two metrics:
The min and max of the datetime field I use as the timestamp.
Changing the timespan of your visualization will give you the first and last entry datetimes.

Resources