Year to Date Function in Direct Query mode - powerbi

I have a measure with year to date function and I want to replicate it in Direct query mode but it's not allowed, do you know some alternative ?
Thanks

Related

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

power BI relative date filter

Relative Date Functionality in Power BI:
Issue #1:
Hi Team,
Need to know is there any way to implement the below relative date filter functionality in Power BI
Please note the following:
For year the base year should be current year, for now it should be 2021
For month the base month should be current month, for now it should be july and so on.
Issue#2:
Based on the above, we want to implement a functionality based on the below selection, where in if we select week, then we should see the count of a metric only for the weeks which are passed by the above filters and similarly for months, days etc. For eg, if we select year, then we should get the count for the year 2022 only as this is the only year passed by the above filter.
Thanks for any help!
Technically possible? I think so. Feasible? No, not really.
While there is some playroom with bookmarks, custom graphics and clever use of a wide range of measures and calculation groups - it would be an enormous task to get everything running correctly and smoothly.
Perhaps one option is to introduce this filtering functionality via a custom visual that takes your date column as input?

making sql query dynamic based on slicer date

I am a new user of power bi and i wanted to know two things.
Is it possible to get data from mysql datasouce in real time based on query.
how to dynamically change the mysql query parameter based on slicer. e.g. if i have a query
select * from table name where date = 10/12/2019
than i want to change the date dynamically based on slicer visual
say in my slicer i have dates of different months and I select 12/01/2020 from slicer than the above query should act based on 12/01/2020 i.e select * from table name where date = 12/01/2020
How can i achieve this in power bi?
What you are looking for is called Direct Query, but that's not supported for MySQL data sources. (Datasource supported feature list)
You might be able to do some tricks on PowerBI Desktop using templates and ask for parameters first, then run a query. But that's not the proper usage of the functionality and you won't be able to use it anyway in the PowerBI Service (since you can't deploy a template). This also tends to be tricky and requires a good amount of manual work in M language (Power Query)
Summarizing, for your case I think the answer is no.

Need date hierarchy for a column, otherwise DATEADD doesn't work

so I am running a DAX query where I compare 2 date columns (both have full date, no time included) and need to figure out, whether one is still valid (within range), if I add 56 days to the other - using the DATEADD function for this.
It worked before, when I had the date hierarchy in the model, seems like Power BI only accepts .[Date] notation, meaning that
DATEADD(InvoiceDueDate; 56; DAY)
won't work, but
DATEADD(InvoiceDueDate.[Date]; 56; DAY)
will work.
Still, I needed to manage relationship model in the data model and I ended up with date hierarchy lost for this column and to use it with .[Date] won't work now.
What are my options now, is there a way to return back the date hierarchy for a column? I tried googling this but came empty handed, there are results, but not entirely valid for my problem. Also DATEADD should obviously work with date column since it is a column of data type Date, but it doesn't. Would be so thankful for any help here. Thanks a lot!
Not a solution but a workaround:
InvoiceDueDate + 56
You can simply avoid using DATEADD if you don't need to add intervals other than day.

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

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)