Specify todays date in REST API call when getting data in Power BI - powerbi

I am using Power BI and getting data from a REST API. I want to specify the date range for the results to be from a specified end date to todays date. What is the correct syntax for this? I have tried TODAY() but that does not appear to work and need the date time to be in the format below.
Source = Json.Document(Web.Contents("https://mywebsite.com/v1/site/1/records?startDate=2019-05-10T00:00:00.000Z&endDate=TODAY()"), 65001)
Thanks for any help

TODAY() function is DAX function, while this is M code and you should use corresponding date functions. Also, you put TODAY() between the quotes, so it will be sent as is.
You could change your code to look like this:
Source = Json.Document(Web.Contents("https://mywebsite.com/v1/site/1/records?startDate=2019-05-10T00:00:00.000Z&endDate=" & Date.ToText(DateTime.Date(DateTime.LocalNow()), "yyyy-MM-dd") & "T00:00:00.000Z")), 65001)

Related

PowerBI - Draw Line Chart with X Axis Grouped by Date (in Days), When Column contains Full timestamp?

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
)
)

Unable to get Day from date in Power Bi in direct query mode

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])

how can i change the format of the date by using Format Function , DAX , Power BI?

I have a column "Sta" type date/time, and I want to change the format of it to be like this format "YYYYMM", or "MM-YYYY" into a new column.
and this error appears to me each time I want to change the format of the column into the new one !!!!
any idea how can I change the format by using the Format Function?
It's explicitly stated in the documentation that FORMAT function is not supported for use in DirectQuery mode. Also take a look at DAX formula compatibility in DirectQuery mode article.
The format function you use expect just one row. With a Max() function before it will work.
However, what you are looking for is in the relationship tab:
Click on your date column then go to Properties > Date time Format > Custom Format:
Here you can type in your custom format.

Power BI visualization of data with a Start and End date

THis is an example of what I think i need to do
I would like to ask some modeling advise I cannot solve myself:
I am using Power BI to visualize the time machinery is out of order.
The source is a register of equipment not functioning, with a start date and end date (note that there is no end date if the machine is not fixed yet).
I would like to show the time (hours, percentage, etc) that the machinery is out of order, filter for a specific period /date (e.g. month).
So I have 2 date columns: ‘’Start out of order’’ and ‘’Back in order’’
I do have a date table, which I usually would connect to all the date variables. However, since I am working with a Start and End date. This does not give the result I am looking for.
Any help is very much appreciated!
Kind regards,
Link to my Power BI FILE:
https://wetransfer.com/downloads/83ca3850392967d0d42a5cc71f4352c420200213160932/eb7353
Stijn
I am not sure how you would like to visualise your data, but this is what I managed to do:
create a daysdiff column with
Daysbetween = IF(ISBLANK(TF_Eventos
[End out of order]);DATEDIFF(TF_Eventos[Start out of
order];TF_Eventos[TODAY];HOUR);DATEDIFF(TF_Eventos
[Start out of order];TF_Eventos[End out of order];HOUR))
This creates your column to check difference between Dates.
Then create a separate column with your Date. In this case I copied the Start out of order date, since I thought you might wanted to be able to filter for the start dates. Then simply create a relationship between your newly created Date column and your start out of order date.
Doing so lets you create a visual with the daysbetween (in this case portrayed in hours) and your start dates. Now just simply add a slicer and you can filter on date.
Hope this helps

Format date field in Power BI service

I have imported an Excel file to Power BI service from my OneDrive for Business.
The file contains a simple Excel table and one of the fields is a date.
Now, in Power BI service, I get that field displayed as a whole number which isn't very useful to read in a report.
How do I change the field to display as date?
Thanks!
We can use FORMAT() method to format date value, Use below mentioned formula
Syntax: Column = FORMAT(Table[column],"MM/DD/YYYY")
Column = FORMAT(DailyActiveUsers[startDate],"MM/DD/YYYY")
Before my data:
After my data:
This usually works by default for true Excel dates. Anyway, just open the Edit Queries window and navigate to your table. In the column header for your Date, change the Data type to Date. Close & Apply to see the result in your report.