I am trying to use current_date function in my BQ query to fecth today's data, but it was not working. After debugging I found out this function returns yesterday's data.
Unfortunately I am not able to add screenshot here.
Below is the query that I ran
Select current_date as the_date
result = 2020-08-20
it should be 2020-08-21
Any idea how to resolve this or how to fetch current datein big query
If you don't specify a time zone, it uses the default for your project. I would guess your default is mis-configured.
Running these queries returns different results.
select current_date('US/Pacific') as the_date
select current_date('Australia/Melbourne') as the_date
Allowable time zone values are here, also on how to use the current_date().
Related
I've been trying to figure this for several hours now.
In my SQL table I have a full timestamp column, with date and time of the action, e.g. last time a user was logged in.
Say I have two users who logged in today so far, in different hours. I want to see "2" log ins for today's Date, instead of seeing them broken down further into exact timestamps.
See screenshot for example
What's the easiest way to do this?
EDIT:
Seems like the whole issues stems from my desire to use "Direct Query" method to load the data.
If I'm just importing the whole table (as users_table (2)), Then yes, I can create a new column with this syntax:
Column = 'users_view (2)'[last_active].[Date]
And plot the graph that I Want.
However, I am unable to create this column on direct query mode. Trying to create this column leads to an error:
Column reference to 'last_active' in table 'users_view' cannot be used
with a variation 'Date' because it does not have any.
If such basic functinoally is not possible, then what's the merit of Power BI? my use case is to create a REAL time dashboard.
Seems like if I want to have anything in real time, it means I can't build even the most basic graph, and vice-versa.
So either I'm missing something, or Power BI is worthless for real time reporting.
You need to follow these steps:
In your fact table, create a new column that corresponds to the date of the timestamp (this will be a grouping dimension column for your timestamps)
Add a measure that counts rows of your table
In a new chart, e.g. line chart, bar chart, whatever - use the date column as X-axis information, and the row count measure as your Y-axis information
Edit: Since it is now apparent you insist on using Direct Query for this - it would appear your data is not in the correct format to support what you want to do. The solution would be to provide Power BI with the correct format for the analysis you want to do. Like adding a column in your SQL database table.
A very costly way of calculating "something" useful would be to do a cumulative count based on timestamp that resets daily. This will look messy but for a site with a lot of activity it will be able to plot something. But it will be slow - since obviously we are far, far away from what would constitute a "sensible" use-case for Power BI using Direct Query.
Cumulative Daily Logins =
VAR _max_time = MAX ( users_table[last_active] )
VAR _date = DATEVALUE ( _max_time )
RETURN
COUNTROWS (
FILTER (
ALL ( users_table ) ,
users_table[last_active] <= _max_time
&& DATEVALUE ( users_table[last_active] ) = _date
)
)
I am using direct query mode in power Bi, and I unable to use format function or add column from query editor. I want Day like this table:
Full Date
Day
21/10/2022
21
1/5/2022
1
Is there any other way I could get Day from date in direct query mode?
There are many ways you can extract day from date. You can use DAX
Day = day(Data[Full Date])
OR
Day = VALUE(FORMAT(Data[Full Date],"dd"))
You can also do it at query editor by going to add Column>>date In the drop down day then day
Having said that in direct query mode you will have to do it at the source. where the data is coming from
We can just use day function. We could not use format function as it does not work for direct query mode.
DayNum = DAY(Data[Full Date])
I am making a demo IoT device monitoring dashboard. I can't understand which function should I use to check if devices are online on a certain date.
This is my sample report table1 from which I separate the Date to another column.
A device can report multiple times on a single day on the server. If it doesn't hit the server no report will generate.
Then I created a lookup table2 that contains all the device ID.
Now I created another table3 and generate a calendar date which I link with the table1 date.
Now In the column, I put my device ID and want to fill the column as true or false if the device reported on a particular date. I am unable to do it.
I used IF ( ISBLANK ( COUNTROWS ( RELATEDTABLE this function it didn't work
I want to create something like this. Which will look up the ID and date to report like it.
It will be a great help if anyone can share any idea.
The screen shots below give you everything you need.
There is a Device Connections table of the devices and when they connected. I have converted the DateTime to a date so that it can be joined to the Dates table, just a list of dates you want to check connections for. I have a relationship that connect the dates of the two tables.
Note: You could also preserve the time at which the device was seen if
needed. It is probably best to have it as a separate column. I have
discarded the time for simplicity.
I have created a single measure:
HasBeenSeen = IF (CALCULATE(COUNTROWS(DeviceConnections)) > 0, TRUE, FALSE)
Which gives a TRUE/FALSE if the device has been seen or not for whatever context exists (e.g. a given date). You could also just count the number of occurrences and display them.
Then I created a matrix visual with the Date from the dates table on the rows, Device ID on the columns and HasBeenSeen as the values to give the desired result.
As I said in the comments to you question, if you accept BLANK in cells where you shown FALSE, you can apply this simple steps. Only Table1 is sufficient for this and need no other table or joining.
Create a very simple Measure like below.
true_false = "True"
Now add a Metrics and configure it as below-
And here is the final output-
I'm trying to create a GCP billing report for my org by fetching data from bigquery to data studio. Pretty new to sql programming in general, I've used the following query to visualize data in data studio.
SELECT
project.name AS project,
EXTRACT(MONTH FROM usage_start_time) AS month,
ROUND(SUM(cost), 2) AS costs,
ROUND(SUM((SELECT SUM(amount) FROM UNNEST(credits))), 2) AS credits
FROM `bqutil.billing.billing_dashboard_export`
GROUP BY project, month
ORDER by project, month
Now, i would like to add custom date range so that viewers can use it to get required report. However, the default custom range provided in in DS does not work. I'm from system admin background pretty new to bigquery and sql in general. Any help with the query would be appreciated.
Thanks
I have performed some tests and I found out the reason why, you are not being able to filter your data by date.
Since the dataset you are using is public I was able to use it to perform what you aim. I will describe my steps to achieve it:
Go to Data Studio >Create(upper left in the console)>Data source
Click on BigQuery
Click Custom query(left side of the window)
Type your query inside the query editor under Enter custom query(on the right side of the window)
On the upper right side of the screen click Connect
Click on FIELDS and check if all the fields have the appropriate type. Please double check the date field, it must be with date format
Create a table with the desired fields. In my case, I used two tables with the following characteristics:
Table 1:
Data source: BigQuery
Date range dimension:month - Please DO NOT forget this field
Dimensions: project, credits and month
Metric: SUM(costs)
1st sort: month
2nd sort: costs
And another table:
Table 2: heat map
Data source: BigQuery
Date range dimension:month - Please DO NOT forget this field
Dimensions: project
Metric: COUNT(project), AVG(cost), MIN(cost), MAX(cost)
1st sort: cost
After configuring the table as described above, click at Date range filter in the tool bar (above the canvas). Drop it at your canvas
Now change the dates accordingly, the values should change
I found out that the dates filter do no work when Date range dimension is not set to you data field in the tables you want to filter by date.
Furthermore, I have also used the following query to test the date range filter. Below is the query:
SELECT
project.name AS project,
cast(FORMAT_TIMESTAMP("%Y-%m-%d" , usage_start_time) as date) AS start_date,
ROUND(SUM(cost), 2) AS costs,
ROUND(SUM((SELECT SUM(amount) FROM UNNEST(credits))), 2) AS credits
FROM `bqutil.billing.billing_dashboard_export`
GROUP BY project, start_date
ORDER by project, start_date
Notice that I just changed the month field to start_date as YYYYMMDD.
i'm trying the new Power BI (Desktop) to create a barchart that shows me the duration in days for the delivery of an order.
I have 2 files. 1 with the delivery data (date, barcode) and another file with the deliverystatusses (date, barcode).
I Created a relation in the powerBI relations tab on the left side to create a relation on barcode. 1 Delivery to many DeliveryStatusses.
Now I want to add a column/measure to calculate the number of days before a package is delivered. I searched a few blogs but with no succes.
The function DATEDIFF is only recognized in a measure, and measures seem to work on table date, not rowdata. So adding a column using the DATEDIFF function doesn't work.
Adding a column using a formula :
Duration = [DeliveryDate] - Delivery[OrderDate]
results in an error that the right side is a list (It seems the relationship isn't in place)?
What am I doing wrong?
You might try doing this in the Query window instead since I think each barcode has just one delivery date and one delivery status. You could merge the two queries into a single table. Then you wouldn't need to worry about the relationships... If on the other hand you can have multiple lines for each delivery in the delivery status table, then you need to get more fancy. If you're only interested in the last status (as opposed to the history of status) you could again use the Query windows to group the data. If you need the full flexibility, you'd probably need to create a Measure that expresses the logic you want.
The RELATED keyword is used to reference another table. Update your query as follows and it should work.
Like this:
Duration = [DeliveryDate] - RELATED(Delivery[OrderDate])