DAX query for sales between dates - daxstudio

find out sales by using DAX query for last January 2022 to january 30/2023.please give me the solution
I tried by using TOTALYTD

Related

Query to return data for the past 6 months

I'm having some troubles in trying to figure out a date criteria in a query. Basically, I'm trying to get all the data from the past 6 months. For example, the current month is December 2017; I would like the query to return data ranging from June to December 2017. I've tried the following criteria:
Between Date() and DateAdd ("M", -6, Date())
However, the criteria returns data based on the day of the date; if the current date is 2 December 2017, the query returns dates from 2 June to 2 December 2017. I want the query to return data from the whole month of June (therefore if we're following the previous example, data from 1 June 2017 will be included too) to December. How do I go about achieving this?
The problem you're having sounds quite simple. You really just need to use the 1st day of the current month, instead of the current date.
There are many ways to get the first day of the current month, for example:
Date() - Day(Date()) + 1
While there are alternate ways to do this, try not to rely on casting a date to a string and back for performance/locale incompatibility
If you use this approach, your SQL WHERE would be:
Between Date() - Day(Date()) + 1 and DateAdd ("M", -6, Date() - Day(Date()) + 1)

SQL query not returning all days from timestamp

I need to run an sql query grouping each data by date. My column in named created and is a timestamp. The query works fine using YEAR(created), MONTH(created), WEEK(created) and shows all the results, however, with day it shows only a range. How can I solve this?
query with YEAR or MONTH or WEEK(created)
SELECT created
FROM mimesi_indexer.meta_served_clips
GROUP BY YEAR(created) //<-- that can be either YEAR, MONTH or WEEK
This query returns all data divided into year, months or weeks between 3rd of March 2017 and today
query with DAY(created)
SELECT created
FROM mimesi_indexer.meta_served_clips
GROUP BY DAY(created)
This query, however, returns all data divided days only between 3rd of March 2017 and 31st of March
The answer is to use DATE(created) instead of DAY(created). Because Day() returns the day of the month (1-31) not the date.

SSRS 2008 R2 Report. Change month grouping from calender month

I have a report that outputs relatively simple counts of clients. It outputs everything from a system as data parameters are not required. They want to see everything.
The thing that is throwing me is, they want months grouped by the 24th of one month to the 23th of the next month.
For example, the month of October 2016 should count all data between the 24th October 2016 TO 23rd of November 2016, the previous Septeber should group everthing between 24/09/2016 to 23/10/2016 etc etc.
In short, is it possible to group month using 24th of that month to the 23rd of the next month?
Happy to provide more information, a bit new to advanced ssrs tasks like this. I did search for solutions like this but couldnt find anything suitable. Any help greatly appreciated.
This requirements can be implemented by enhancing your query. Say f.e., you have the following:
select
t.Date,
t.AggregatedField
from SomeSchema.SomeTable as t
You can do next:
select
MonthNumber =
case
when DATEPART(DAY, t.Date) >= 24 then DATEPART(MONTH, t.Date)
else DATEPART(MONTH, t.Date) - 1
end,
t.AggregatableField
from SomeSchema.SomeTable as t
The output you will get will be like (month_number, field_to_aggregate). You then need to group data by that month_number, you can do that directly in SQL, or using RDL report grouping (consider that first provides the best performance).
To construct month name, you will probably need to extract year number to like this:
DATEPART(YEAR, t.Date)
and then construct date using month number anhd year number.

Count and group by day MySQL query

How can i count and group by day in MySQL. My issue is that I'm not using a MySQL time stamp.
I'm saving my date in below format
date("F j, Y");
So the date will be November 24, 2015, November 25, 2015, November 26, 2015 etc.
Can i keep the format as it is and count and group by day?
The answer is - technically - yes, you can groupy by day and keep this format using mysql's str_to_date() function to convert your string to a date type and extract the day part out of it using one of the day related functions.
The question is, why would you do this? You should store the date either in a timestamp or datetime column and format the dates to your specification when you query it using date_format() function. This way you can retrieve the dates in the desired format and you retain the ability to easily perform date arithmetic within your sql code.

My SQL query to list dates that have no records

I have an online calendar system that I use for tracking my band's gigs - I'd like to construct a query that will display all Fridays and Saturdays that don't currently have a record assigned to them.
eg,
if I have a record in the DB for Friday 23rd Aug and Friday 30th Aug (records being gigs that are booked), what would the query cirteria be to output Saturday 24th Aug (as it has no record)?
Select * from ['giglist']
where ['gigdate'is in 'friday','saturday']
and ['gigdate' doesn't have a record]
I will probably set the days of the week as variables so that the user can run the query for any day or selection of days.
Thanks,
Darren
if assuming from your question there is a field gigdate of date type that keeps date information and a seperate record field.
Then query would be,
select DAYNAME(gigdate), DAYOFMONTH(gigdate), MONTHNAME(gigdate) from giglist where
DAYNAME(gigdate) in ('Friday', 'Saturday') and
recordfield is NULL;
It's better to use single date type field and just store date only, as mysql has powerful set of date functions to help you out for your needs.