Get months names between two dates Ms-Access - date

I have this query
SELECT TblSales.ProductCode, TblSales.ProductName, TblSales.QtySold, Right([Zdate],7) AS [Mn/Yr]
FROM TblSales
WHERE (((TblSales.zDate) Between [Forms]![FrmSales]![From] And [Forms]![FrmSales]![FinalTo]))
GROUP BY TblSales.ProductCode, TblSales.ProductName, TblSales.QtySold, Right([Zdate],7);
I need this result to be like these columns (ProductCode-ProductName-Sum Of QtySold in First month from the given date - Second month - Third month - and so on)
Example : If the two dates were #1-1-2018# To #31-3-2018# -These dates can be changed due to [Forms]![FrmSales]![From] And [Forms]![FrmSales]![FinalTo]-
Columns:
ProductCode -ProductName -Jan-2018 -Feb-2018- March-2018
Rows:
A1-Computer-2000-2500-3000
Previous Qty is the SumOfQtySold in every month between the two dates,Thanks in advance.
Edit #1 :
I couldn’t make a crosstab query and this message popup Crosstab Error

You can use a crosstab query to transpose row data into columns. Something like this:
PARAMETERS StartDate DateTime, EndDate DateTime;
TRANSFORM NZ(Sum(tblSales.QtySold), 0) AS SumOfQtySold
SELECT tblSales.ProductCode, tblSales.ProductName
FROM tblSales
WHERE (((tblSales.zDate) Between [StartDate] And [EndDate]))
GROUP BY tblSales.ProductCode, tblSales.ProductName
PIVOT Format([tblSales].zDate,"mmm-yyyy");

Related

DAX Calculate Billing Days Between Two Variable Dates

I have a dimdate table that is represented below. I have each day flagged as BusinessDay Y/N. I also have a DimSalesRep table that has a daily goal for each rep. I want to be able to allow users to input a StartDt and EndDt with filters on the report and have a calculated column look at the business days between those dates. I can calculate daysbetween with defined dates but I am unsure how I would use DAX with variable dates that are applied through Report filters.
I should also note I am not sure how best to handle a startdt and enddt filter based of the column, TheDate
Cheers!
Reference your dimdate table twice
StartDate = 'dimdate'
EndDate = 'dimdate'
and use this measure:
Num BusinessDays =
CALCULATE(
COUNTROWS('dimdate'),
'dimdate'[BusinessDay] = "Y",
'dimdate'[Date] >= SELECTEDVALUE(StartDate[Date]),
'dimdate'[Date] <= SELECTEDVALUE(EndDate[Date])
)

How to count events after set date with COUNTIFS?

I'm creating this report in spreadsheet
https://docs.google.com/spreadsheets/d/1U48MybVshKT3eRYE9goRCab9k1KCoXe7Zsr9Ogkkm4Y/edit?usp=sharing
In "BD" you can find the records and in "NB-month" the KPI that I want to analyze; I would like to create DATE filter for the numbers in the columns, ex for the col: "nº Contract closed" I'm thinking to use this formula:
=COUNTIFS(BD!R:R;A5;BD!G:G;">"&DATE(B2))
but I get a value: "0" that is incorrect because for this agent "Carla Vaello" the number of contracts closed after 2020-02-01 should be "2".
your usage of DATE formula is wrong (DATE requires 3 parameters). either change DATE to DATEVALUE or use:
=COUNTIFS(BD!R:R; A5; BD!G:G; ">"&B2)

Create a measure to return the maximum date about the order in a fact table. (SSAS Multidimensional)

I want to create a measure which return the maximum date about Orders but before the actual day
I will write an example :
My tables here
(In my table Calendar i have the year 2016,2017,2019, and in my Order table, i have an order for 2016 and 2019,
I want the last date order but before the actual day (18/05/2017), so i want the Date 01/01/2016).
I have 2 table, a dimension Calendar and a fact table Order.
I was thinking about the function filter, so i search how to use filter in
google, and all the solutions i found use 'With' and 'Select'.
(I can't use 'With' and 'Select' when i create a measure in SSAS multidimensional).
Hope i will see your advice.
Just like this similar case in adv cube?
[max order date] return the maximum date about [Internet Sales Amount]
with member [max order date] AS
tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales Amount])).item(0).item(0).PROPERTIES( "name" )
select {[max order date] } on 0 from [Adventure Works]
if yes, then you can create a measure in your cube like this:
Create Member CurrentCube.[Measures].[max order date]
As tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales
Amount])).item(0).item(0).PROPERTIES( "name" );
if only till current day, then(following is refer to adv cube, you need do some code changes per your cube):
Create Member CurrentCube.[max order date] AS
Tail
(
NonEmpty
(
{
Head([Date].[Date].[Date]).Item(0).Item(0)--the first day in your Date dim
:
StrToMember("[Date].[Date].&[" + Format(Now(),"yyyyMMdd") + "]")-- as of current day
}
,[Measures].[Internet Sales Amount]
)
).Item(0).Item(0).Properties("name")
IDE to Write, Analyze, Tuning, Debug MDX efficiently (www.mdx-helper.com)

Bulk insert with variable date field for non existing dates?

Attendence
(
Stu_id int
Att_Id int
Att_Date datetime
Att_Num numeric(15,5)
)
This table basically contains attendence records. I am trying to find the logic to enter the rows for missing dates from 1 Jan 2012 till today.
Assume there is a single attendence record for this period row (1,1,'2012-05-06',1.20000). Then I would like to insert rows for each day from 1 Jan 2012 till today except the existing date with the same values for all the fields except the date field which should be the actual date.
I am trying to bulk insert all the rows but don't know how would I adjust the date field
and check for the existing date.
Thanks.
Try a stored procedure which loops through the dates.
Or better yet, make a dates table and select from that. This will be much faster. Something like:
INSERT INTO Attendence (Stu_id, Att_Id, Att_Date, Att_Num)
SELECT a.Stu_id, a.Att_Id, d.TheDate, a.Att_Num
FROM Attendence a
INNER JOIN Dates d ON d.TheDate BETWEEN '2012-01-01' AND GETDATE()
AND d.TheDate <> a.Att_Date
I would use the DateDiff function to figure out the amount of days inbetween the date in the function and the date in question. Make a DateTime variable and give it the value of 1 Jan 2012. Then set up a while loop that loops the amount of days from the DateDiff function.
In psuedo, the while loop would look something like this.
#DaysTill = DateDiff(days, 1/1/2012, #SomeDate)
While #DaysTill>0
##Check = Select Count(Att_Date) From Attendance where AttDate = DateAdd(days, #DaysTill, Jan 1st 2012)
IF ##Check = 0 THEN Insert Into Attendance VALUES #Stu, #Id, DateAdd(days, #DaysTill, Jan 1st 2012), #numeric
#DaysTill = #DaysTill - 1
END
The main things are understanding DateAdd and DateDiff. After that everything becomes relatively simple.

Date range in PostgreSQL

When I apply a date range to my query, is there anyway to display the dates used in the date range even if there is no data at those dates?
Suppose I use,
... where date between '1/12/2010' and '31/12/2010' order by date
What I want in my result is to show sum of all amount column until 1/12/2010 on that day even if there is no data for that date and also same for 31/12/2010.
Join with generate_series() to fill in the gaps.
Example:
CREATE TEMP TABLE foo AS SELECT CURRENT_DATE AS today;
SELECT
COUNT(foo.*),
generate_series::date
FROM
foo
RIGHT JOIN generate_series('2010-12-18', '2010-12-25', interval '1 day') ON generate_series = today
GROUP BY
generate_series;
Result:
0,'2010-12-18'
0,'2010-12-19'
1,'2010-12-20'
0,'2010-12-21'
0,'2010-12-22'
0,'2010-12-23'
0,'2010-12-24'
0,'2010-12-25'