end of month/year data in tibco spotfire - spotfire

I have the following dataset in tibco spotfire:
Original data
I want to bring the amount of item in the beginning of each month for each row and get the following result:
Image
Any suggestions?
The dataset looks like this: I have got maximum amount for previous month, but I want to get the amount of the last day of the previous month.
enter image description here

I could do it via an intermediate column (as Spotfire's OVER does not accept expressions).
First calculate the year and month like this:
(assuming the format of your date is known and stable)
[YearMonth] is :
Integer(Concatenate(Substring(String([Date]),7,4),Substring(String([Date]),4,2)))
then your [Previous Month] is:
Max([Amount]) over (Intersect(Previous([YearMonth]),[BRANCH],[CLASS]))
and your [Diff] is:
[Amount] - [Previous Month]
Revised after comment 19 August:
change the Max to ValueForMax and insert the day of the month, so that the formula calculates the value
corresponding to the last recorded day for that month:
ValueForMax(DayOfMonth([Date]),[Amount]) over (Intersect(Previous([YearMonth]),[BRANCH],[CLASS]))
Revised after comments 6 October:
if Substring(..) is not available, here is an alternative solution:
Create a new column (to make the expressions understandable): [StringMonth] as:
If(LongInteger(Month([Date]))>10,String(LongInteger(Month([Date]))), Concatenate('0',String(LongInteger(Month([Date])))))
Then calculate your [YearMonth] as:
Integer(Concatenate(Year([Date]),[StringMonth]))

Related

How can I extract a total count or sum of agents who made their first sale in a specified month?

I am trying to extract some data out of a large table of data in Excel. The table consists of the month, the agent's name, and either a 1 if they made a sale or a 0 if they did not.
What I would like to do is plug in a Month value into one cell, then have it spit out a count of how many agents made their first sale that month.
Sample Data and Input Output area
I found success by creating a secondary table for processing a minif and matching to agent name, then countif in that table's data how many sales months matched the input month. However I would like to not have a secondary table and do this all in one go.
=IF(MINIFS(E2ERawData[Date Group],E2ERawData[Agent],'Processed Data'!B4,E2ERawData[E2E Participation],1)=0,"No Sales",MINIFS(E2ERawData[Date Group],E2ERawData[Agent],'Processed Data'!B4,E2ERawData[E2E Participation],1))
=COUNTIFS(ProcessedData[Month of First E2E Sale],H4)
Formula in column F is:
=MAX(0;COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1)-SUM(COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;IF($A$2:$A$8=E3;$B$2:$B$8))))
This is how it works (we'll use 01/03/2022 as example)
COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1) This counts how many 1 there are for the proper month (in our example this part will return 2)
COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;SI($A$2:$A$8=E3;$B$2:$B$8)) will count how many 1 you got in previous months of the same agents (in our example, it will return 1)
Result from step 2, because it's an array formula, we sum up using SUM() (in our example, this return 1)
We do result from step 1 minus result from step 3 (so we get 1)
Finally, everything is inside a MAX function to avoid negative results (February would return -1 because there were no sales at all and agent B did a sale on January, so it would return -1. To avoid this, we force Excel to show biggest value between 0 and our calculation)
NOTE: Because it's an array formula, depending on your Excel version maybe you must introduce pressing CTRL+ENTER+SHIFT
If one has got access to the newest functions:
=LET(X,UNIQUE(C3:C9),VSTACK({"Month","Total of First time sales"},HSTACK(X,BYROW(X,LAMBDA(a,SUM((C3:C9=a)*(MINIFS(C3:C9,D3:D9,D3:D9,E3:E9,1)=C3:C9)))))))

Create Date from MM/DD format and include current year? Power Query

I have a table that has a series of Columns with data I need to split out. Example below
STATUS#10/16 12:00:00 (CODE)
I've been able to split it easy enough and when I originally tried to set the date on an older dataset it identified it as a date e.g. 16th Oct 2021 However I started to get errors on this date column and trying with different datasets (10/12, 10/13, 10/14) it is not finding the date. I tried the following query code but I'm receiving errors
[STATUS DATE] is split to 10/14, 10/15 etc
#date( Date.Year(DateTime.LocalNow), Date.Month(Text.End([STATUS DATE]), 2), Date.Day(Text.Start([STATUS DATE]),2))
However I'm getting a function error so I tried
Date.From(Date.Day(Text.Start([STATUS DATE]),2) & Date.Month(Text.End([STATUS DATE]),2) & Date.Year(DateTime.LocalNow)
I have also tried to do this from an example column however the query created is looking at the cell value e.g. if 10/14 then 14/10/2021 else if 13/10 then 14/10/2021. This method i feel is prone for error once I include a larger dataset.
Is there anyway I can determine the date value based on mm/dd format? But with year end in mind, make the YYYY be determined by current year unless we move into Jan and then I don't want the Oct, Nov, Dec value showing as 2022.
You don't really show what your original data looks like.
But if it is like:
Source
Then you can use this code in the Add Custom Column dialog:
let
split=Text.SplitAny([STATUS DATE],"#/ "),
mnth = Number.From(split{1}),
dy = Number.From(split{2})
in
#date(Date.Year(DateTime.LocalNow()),mnth,dy)
The Text.SplitAny function lets you input a list of delimiters and the text will split on all of them. So it is relatively simple to extract the month and day values
to create:
Split [STATUS DATE] one more time into [Month] and [Day] column, using the "/" as a separator. Then you don't have to bother with 1 or 2 digit numbers and you can simply use this formula:
#date(Date.Year(DateTime.LocalNow()), [Month], [Day])
DateTime.LocalNow() is a function, so you need to add the brackets.
[Month] and [Day] are numbers already, so you don't need the Date.Month() or Date.Day() functions.

Excel Using concatenate to compare dates

I have a table containing several columns of which one is a date/time field. I am trying to get a count of instances per day using the following
=COUNTIFS(Table4[Data],"Apple",Table4[Date],(CONCATENATE(V4,"*")))
Data Date Comp Date Count
Apple 6/12/18 1:00 PM 6/12/18 12:00 AM 0
Apple 6/12/18 7:00 AM
Orange 6/12/18 1:30 PM
Apple 6/11/18 11:23 AM
From my understanding of all the moving parts here I should be checking to see if "Apple" exists in the data column and then if "6/12/18" with any amount or type of characters after it exists. If both are true I will then get a count + 1 leaving me with a value of 2 in the above example.
What I actually get however is a 0 unless I match the time portion of date the data to be exactly the same and then removed the wildcard ,"*" from the equation.
Am I doing something wrong or can the wildcard not be used to accomplish what I am trying?
Thanks!
I think you should set your criteria properly.
If you add an additional column next to your Date that contains calculates the integer value of your date using INT() and format the display as DATE (m/d/yyyy) you should then be able to use the following COUNTIFS formula
=COUNTIFS(Table4[Data], "Apple", Table4[Date], "=6/12/18")
See the explanatory video from their Office' support site: https://support.office.com/en-us/article/countifs-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842
If your [Date] column is a datetime or smalldatetime, you can work with it using CONVERT function, depending on how you want to group.
For example, if you don't care about the time to do the group, you could use the next query:
SELECT CONVERT(varchar,[Date],103), [Data], COUNT(*)
FROM [test_delete].[dbo].[Table1]
GROUP BY CONVERT(varchar,[Date],103), [Data]
This should result in something like this:
[Date] [Data] [Count]
11/06/2018 Apple 1
12/06/2018 Apple 2
12/06/2018 Orange 1
Hope this helps you
If your dates are stored as dates instead of text, use the following:
=COUNTIFS(Table4[Data],"Apple",Table4[Date],">="&V4,Table4[Date],"<"&V4+1)

How to find the first date of the month for a set of data in vba

I have a set of data as such:
05/06/2015
04/06/2015
03/06/2015
02/06/2015
29/05/2015
28/05/2015
27/05/2015
26/05/2015
25/05/2015
22/05/2015
21/05/2015
20/05/2015
19/05/2015
18/05/2015
15/05/2015
14/05/2015
13/05/2015
12/05/2015
11/05/2015
08/05/2015
07/05/2015
06/05/2015
05/05/2015
04/05/2015
30/04/2015
29/04/2015
28/04/2015
27/04/2015
24/04/2015
23/04/2015
22/04/2015
21/04/2015
20/04/2015
17/04/2015
16/04/2015
15/04/2015
14/04/2015
13/04/2015
10/04/2015
09/04/2015
08/04/2015
07/04/2015
06/04/2015
02/04/2015
01/04/2015
31/03/2015
These refer to the weekdays in a year. Among these dates, I want to find the first date of the month. So for example, the month of June, the first date to be identified should be 02/06/2015 and for May be 04/05/2015.
I have tried something like this:
=IF(Cellreference=((Cellreference)-DAY(Cellreference)+1),TEXT(Cellreference,"mmm"),"")
But this only takes the first date of the month. I want it to be the first date in the month in the list of dates given.
Need some guidance on how to achieve this.
I see you use Formula so I can only suggest below:
=MIN(IF(MONTH(AllDateReference)=MONTH(CellReference),AllDateReference,1E+99))
This is an array formula entered using Ctrl+Shift+Enter.
Actual sample:
=MIN(IF(MONTH(A$1:A$46)=MONTH(A1),A$1:A$46,1E+99))
where A$1:A$46 contains all your dates.
Edit1: Display on first date of the month only.
=IF(A1=MIN(IF(MONTH(A$1:A$46)=MONTH(A1),A$1:A$46,1E+99)),A1,"")
Sample:

CALM Query to get a specifc day and month from any year

I'd like to create a CALM query to get days and months of any year. Example:
In a list with the results below, I'd like to get all dates that have day equals 10 and month equals 07:
07/10/1984
01/02/2001
05/12/1991
07/10/2007
So, the result would be:
07/10/1984
07/10/2007
I don't think you will be able to do it directly in CAML for any year so you would end up listing out that day and month range for every year - bit of a monster.
Are you able to add extra calculated columns to your list? If so then you can add
DayAndMonth = Day([YourDate]) & "-" & Month([YourDate])
Then its a simple case of filtering using CAML or normal view filter (assuming US date format)
DayAndMonth = "7-10"

Resources