Calculate measure using dates
I am facing difficulty to calculate date difference of two dates
Dimension contains ID, Name, CreateDate, CloseDate
I would like to calculate CreateDate - CloseDate but i am getting #error by creating calculate measure within the CUBE
datediff("d",[Dim].[CreateDate].currentmember.membervalue,[Dim].[CloseDate].currentmember.membervalue)
but same statement is working using MDX
with Member [Measures].[Age] as
datediff("d",[Dim].[CreateDate].currentmember.membervalue,[Dim].[CloseDate].currentmember.membervalue)
select [Age] on 0,
{[Dim].[Id].children*[Dim].[CloseDate].children*[Dim].[CreateDate].children} on 1
from [cube]
Any idea, where am i doing mistake OR what is the way to calculate within the cube?
RaghuM
Hi Raghum,
According to your description, there are two columns CreteDate and CloseDate in your table, you want to add a calculation to calculate the value (CreateDate-CloseDate), right?
In this case, you can add a calculation to your data source view, and then use the calculated column as the new measures. A named calculation is a SQL expression represented as a calculated column. This expression appears and behaves as a column in the table.
Please refer to the link below to see the details.
http://msdn.microsoft.com/en-us/library/ms174859.aspx
Besides, here is a similar issue with your, please see:
http://social.msdn.microsoft.com/forums/sqlserver/en-US/7cbf7471-141f-48ee-a6e3-2f3298dca2eb/date-difference-calculation-in-ssas
Regards,
Charlie Liao
TechNet Community Support
Similar Messages
-
DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file
Hi
DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file
Two main
sections:
1)
Perform
write and read operations to and fro different spread sheet files, such that
each file have a single row of 32bits different binary data (analogous to 1D
array) where the left most bit is the MSB. I don’t want to manually enter the
32 bits binary data, I want the data written or read just by opening a file
name saves with the intended data.
2)
And
by using test patterns implemented using the digital pattern generator or build digital data functions or otherwise, I need to
ensure that the
binary data written to a spreadsheet file or any supported file type
then through the NI-USB 6509 is same as the data read.
I’m aware I can’t use the simulated
device to read data written to any port but if the write part of the vi works I
‘m sure the read part will work on the physical device which I’ll buy later.
My Plan
of action
I’ve
created a basic write/read file task and a write/read DAQ task for NI USB 6509
and both combine in a while loop to form a progress VI which I’m confuse of how
to proceed with the implementation.
My
greatest problem is to link both together with the correct functions or operators
such that there are no syntax/execution errors and thus achieve my intended
result.
This
project is one of my many assignments for my master thesis, so please i’ll
appreciate every help as I’m not really efficient with LabVIEW programming but
I prefer it because is fun and interesting if I get to know it.
Currently I’m
practicing with LabVIEW 8.6/NI DAQmx 8.8 Demo versions and NI USB 6509
simulated device.
Please see
the attached file for my novice progress, thanks in
advance for the support
Rgds
Paul
Attachments:
DIO_write_read DAQ from file.vi 17 KBWhat does your file look like? The DAQmx write is expecting a single U32 value, not an array of I64.
Message Edited by vt92 on 09-16-2009 02:42 PM
"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal -
How to calculate any two date with diffence calculation by using obiee11g?
Hi,
i have a requirement like,
location wise current month and previous month with movement calculation,can to tell me how to calculate any two date with diffence calculation
by using obiee11g
Note,
I tried to implemented ago function as well as dynamic two dates calculation using $2-$1 methods..but i am getting the o/p it's self i am getiing some null value also that' why it's not tallying with our actual report.
i tired to used ifnull(mesaurecolumn,0) also case condition on the mesaure colution still it's not tallying.
THanks and Rds,
Devarasu.RHi,
for Date Difference........
TimestampDiff(interval, timestamp1, timestamp2)
ex:TimestampDiff(SQL_TSI_DAY, cast('1-apr-2011' as date), current_date)
Where:
interval
The specified interval. Valid values are: SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY,
SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, SQL_TSI_YEAR.
Cheers,
Aravind -
Iam doing Data acquisition using NI-PXI 4472 and buffered period Measurement using NI-PXI 6602 simultaneously,my program gives an buffer overflow error
murali_vml,
There are two common buffer overflow and overwrite errors.
Overflow error -10845 occurs when the NI-DAQ driver cannot read data from the DAQ device's FIFO buffer fast enough to keep up with the acquired data as it flows to the buffer (i.e., the FIFO buffer overflows before all the original data can be read from it). This is usually due to limitations of your computer system, most commonly the result of slow processor speeds (< 200 MHz) in conjunction with PCMCIA DAQ boards, which have small FIFO buffers (e.g., the DAQCard-500). Sometimes using a DAQCard with a larger FIFO can solve the problem, but a better solution is to lower the acquisition rate or move to a faster system. Another cause of the -10845 error could be due to an interrupt-driven
acquisition. For example, PCMCIA bus does not support Direct Memory Access (DMA). If the system is tied up processing another interrupt (like performing a screen refresh or responding to a mouse movement) when it is time to move data from the board, then that data may get overwritten.
Overwrite error -10846 occurs when the data in the software buffer that you created for an analog input operation gets overwritten by new data before you can retrieve the existing data from the buffer. This problem can be solved by adjusting the parameters of your data acquisition, such as the lowering the scan rate, increasing the buffer size, and/or increasing the number of scans to read from the buffer on each buffer read. Additionally, performing less processing in the loop can help avoid the -10846 error.
See the NI-DAQ Function Reference Manual for a listing of all NI-DAQ error codes.
Have a great day. -
Measure using UseRelationship not working well when sliced with attributes from the same table
Hi,
I have Measure created using the 'UseRelationship' Function, which uses a different datekey to link to the DateDim than the one the table is directly related by. The measure works as expected except in one scenario.
If I browse the measure using an attribute from the same fact table then the attribute is filtered using active relationship whereas the measure is filtered using the inactive relationship as shown below:
FACT(2 rows)(Active Relationship to Date using DateKey1)
SNo DateKey1 DateKey2 Geo Amt
1 20100101 20120101 India 100
2 20100101 20120101 US 200
AmtMeasure:=CALCULATE(SUM([Amt]),USERELATIONSHIP(FACT[DateKey2],'Date'[DateKey]))
If I browse the above measure in excel, with Year selected as 2012, I get 100+200=300. Now if I drag the Geo attribute against the measure I get 2 rows with 100 and 200.
If I do the same in a power view report I don't get any results after dragging the Geo attribute, whereas I get the correct value of 300 without the geo attribute. I checked the DAX query which the power view generates and figured this is being caused because
there are no rows in the table with DateKey1 having year 2012. I understand why this is happening this way in a DAX query and not in MDX, but shouldn't both behave in the same way and what is a work around.
Thanks,
Sachin ThomasSac, is this still an issue?
Thank you!
Ed Price, Azure & Power BI Customer Program Manager (Blog,
Small Basic,
Wiki Ninjas,
Wiki)
Answer an interesting question?
Create a wiki article about it! -
Introduction
In SQL Server Analysis Services (SSAS), you can create a calculated measure in SQL Server Data Tool (SSDT)/Boniness Integrated Development Studio (BIDS). Sometimes you may need to create calculated measure by using AMO in a C# or VB project.
In this article, I will demonstrate so how to create calculated measure using AMO in SSAS?
Prerequisites
Before create calculated measure using AMO, you need to ensure that the following components were installed in your server.
The multidimensional database AdventureWorks Multidimensional Model 2012
A SQL Server with SSIS and SSAS installed
The AMO libraries installed:
X86 Package (SQL_AS_AMO.msi)
X64 Package (SQL_AS_AMO.msi)
Solution
Here is the detail steps to create calculated measure using AMO in SSAS.
Open SSDT and create a new SSIS project.
Drag Script Task to the design surface.
Click SSIS-> Variables to open the Variables window and add two variables that used to connect to the server and database.
Create a connection to connect to SSAS server.
Rename the connection name to ssas.
Double click the Script Task to open Script Task Editor.
Add Connection and Database variables to ReadWriteVariables textbox and then click Edit Script button.
Add AMO reference in the Solution Explore window.
Copy the script below and paste it into the script.
Dim objServer As Server
Dim objDatabase As Database
Dim strDataBaseID As String
Dim objCube As Cube
Dim objMdxScript As MdxScript
Dim objCommand As Command
Dim strCommand As String
objServer = New Server
objServer.Connect("localhost")
objDatabase = objServer.Databases("AdventureWorksDW2012Multidimensional-EE2")
strDataBaseID = objDatabase.ID
If objDatabase.Cubes.Count > 0 Then
objCube = objDatabase.Cubes("Adventure Works")
If objCube.MdxScripts.Count > 0 Then
objMdxScript = objCube.MdxScripts("MdxScript")
objMdxScript = objCube.MdxScripts(0)
Else
objCube.MdxScripts.Add("MdxScript", "MdxScript")
objMdxScript = objCube.MdxScripts("MdxScript")
End If
objCommand = New Command
strCommand = "CREATE MEMBER CURRENTCUBE.[Measures].[Multipy Measures By 3]"
strCommand = strCommand & " AS [Measures].[Internet Sales Amount] * 3, "
strCommand = strCommand & " VISIBLE = 1 ; "
objCommand.Text = strCommand
objMdxScript.Commands.Add(objCommand)
objMdxScript.Update()
objCube.Update()
End If
objServer.Disconnect()
Then you can run this SSIS package to create the calculated measure.
Applies to
Microsoft SQL Server 2005
Microsoft SQL Server 2008
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2012
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Thanks,
Is this a supported scenario, or does it use unsupported features?
For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
in a supported way?
Thanks! Josh -
How to calculate the 'real data of arrival' in PO item
Hi,
Confirmation control keys with control type u201CDAu201D are MRP relevant
1. = New field time of transportation in calendar days
2. = Confirmation control type u201CABu201D (order confirmation)
3. = Confirmation control type u201CLAu201D (shipping notification)
4. = Confirmation control type u201CDAu201D (Date of arrival)
When data 1-3 has been changed = 4 will be calculated again.
Program requirements to calculate the u201Creal data of arrivalu201D:
1. When 1 >0 days then create 4 directly after placement of 2 (2 can be placed manually or automatically)
2. 4 must be calculated: AB delivery date 2 + calendar date amount 1 = arrival date 4 (MRP gets a confirmed delivery date by vendor plus transportation time)
3. When changes in 1 then change 4 (add calendar days to arrival date DA)
4. When changes in 2 then change 4 = u201Cnewu201D delivery date 2 plus calendar days 1 = new arrival date 4
5. When 3 u201CLAu201D is entered (manually/automatically) then calculate: shipping date LA 3 plus calendar days 1 = new arrival date in 4
6. When 1 has been changed then calculate 4 new (Check is 2 existing then use 2, check is 2 + 3 existing then use 3)
7. When 2 or 3 has been changed quantity then also update quantity in 4
8. When 2 has been canceled then cancel 4, too
9. When 3 has an inbound delivery document no. in place then copy the same no. in the inbound delivery field 4 and in the new column in MRP (MD04, see MRP view below)
i have a lot of confuseging in this lines of code,even where u write i don't know in BADI . we are implement in BADI only.
if possiable give me code for this requriment. . this line of code in which method we write,please guide me.............SDN is not your code factory, please research yourself before posting, maybe ask whoever handed you this requirement?
Thread locked.
Thomas -
How to use date function in my procedure
hi Gurus,
i have a requirement
where user passes the end_date parametre from front end which get convered to
End Date => 2012/05/31 00:00:00
now i based on this end date value i have to calculate the start date which is only month less than the end date, i know i can use add_months function for this requirement but
my problem is
l_start_date :=add_months(fnd_date.canonical_to_date(p_end_date),-1);
(OR)
l_start_date := add_months(to_date(end_date,'DD-MON-YYYY'),-1);
all these are returning date format as DD-MON-YYYY eg;
if user passes from front end 31-may-2012 , in the backend to my procedure it is passing as 2012/05/31 00:00:00
and my procedure calculating start date and returning as '01-MAY-12',
but my requiremnt is
it should return
Start Date => 2012/05/01 00:00:00
any pointers on this is highly appreciable,
thanks in advanceeHuaMin Chen wrote:
BluShadow wrote:
HuaMin Chen wrote:
Try
select trunc(to_date('22-AUG-03'), 'MONTH') from dual;?? That is so wrong.
Is that date 22nd August 2003? 22nd August 1903? 3rd August 2022? 3rd August 1922?
You have no date format specified in your to_date function.That is fine for 10g or above versions. Thank you.It way work, if you're lucky, but it depends on your sessions NLS settings...
SQL> select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
TRUNC(TO_DATE('22-AU
01-AUG-0003 00:00:00
SQL> alter session set nls_date_format = 'YYYY-MM-DD';
Session altered.
SQL> select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
TRUNC(TO_D
0022-08-01
SQL> alter session set nls_date_format = 'HH:MI:SS YYYY-MM-DD';
Session altered.
SQL> select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
select trunc(to_date('22-AUG-03'), 'MONTH') from dual
ERROR at line 1:
ORA-01849: hour must be between 1 and 12
SQL>So it's certainly not "fine". It's bad practice.
This must be fine
select trunc(to_date('22-AUG-03','dd-MON-RR'), 'MONTH') from dual;That's better. -
How to use dates/times in the definition of local fields?
Hello!
I have few tough questions for which I haven't found an answer. I hope someone is capable to help me.
1. Is there a transaction to search tables if we know the field?
2. I'd like to define a local field and need to use dates in the calculation function. So basically I need to calculate the lean-time from the date of the purchase order (field BSTDK) to the date of the final delivery (field PLIFTS) and the result should be displayed in weeks. How can I do this? Or can I?
3. Can I use the local fields further in my calculations?
Thank you in advance!
Maria KangasniemiHi,
1. Is there a transaction to search tables if we know the field?
Tcode: SE84
2. I'd like to define a local field and need to use dates in the calculation function. So basically I need to calculate the lean-time from the date of the purchase order (field BSTDK) to the date of the final delivery (field PLIFTS) and the result should be displayed in weeks. How can I do this? Or can I?
Doing some calculation you can define it.
3. Can I use the local fields further in my calculations?
What is local Fields? -
Payment terms should calculate Payment due date based on working days
Hi Experts,
As we know that standard SAP calculates Payment due date= base line date + number of days maintained in payment terms. In this payment days are considered as calendar days and not the working days.
Example: If base line date is Thursday, payment terms says 3 days then payment due date is calculated as Sunday ( which is not a working day as per the factory calendar I use). The requirement is that payment date should be calculated as following Tuesday considering Satuarday and Sunday are not working days as per the calendar.
Can you please suggest how can we achieve this?
Thanks,
RaviYou can not acheive from config pooint of view but you can use BADI and get the solution
use BAdI MRM_PAYMENT_TERMS to set terms of payment
You can use this Business Add-In to change the following fields for the
terms of payment in the invoice document header:
o ZFBDT: Base date for due date calculation
o ZBD1T: Discount days 1
o ZBD1P: Discount percentage 1
o ZBD2T: Discount days 2
o ZBD2P: Discount percentage 2
o ZBD3T: Deadline for net condition
o ZLSPR: Key for payment block -
How to use date functions in BPEL
Hi All,
Is there any wayout for calculating no. of years with a given date and current date in BPEL.
I am developing a small application where I have to calculate the years of experience of the employees. I am given with the date of joining.I want to subtract the date of joining from the current date. Is there any way-out to calculate no. of years from the given date and current date in BPEL using date functions or something else.
Please suggest something..
Thanks in Advance
Roshni Shankaryou could use something like this in xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml"/>
<xsl:variable name="date1" select="xs:date('2001-01-01')"/>
<xsl:variable name="date2" select="xs:date('2010-01-10')"/>
<xsl:variable name="dif" select="$date2 - $date1"/>
<xsl:template match="/">
<all>
<date1>
<xsl:value-of select="$date1"/>
</date1>
<date2>
<xsl:value-of select="$date2"/>
</date2>
<dif-days><xsl:value-of select="fn:days-from-duration($dif)"/></dif-days>
<dif-years1><xsl:value-of select="fn:years-from-duration($dif)"/></dif-years1> <!-- gives 0 for me -->
<dif-years2><xsl:value-of select="fn:days-from-duration($dif) div 356"/></dif-years2>
</all>
</xsl:template>
</xsl:stylesheet> -
Asset Management on BPC: scripts using dates
Hi all,
I wonder whether any of you have already implemented any logic that uses dates, such as a calculation of asset's depreciation based on properties with acquisition dates (to put an example, I'm not exactly doing that). Basically I need to do some calculations about assets taking into account dates (like "begin calculation from date xx/xx/xxxx).
Among the different functions available I don't find any to manage dates and calculate periods from dates. Could you please advice on any best practice/strategy on how to handle this?
Regards,
RafaIf you're running it as batch logic, you have a lot of flexibility using the *SELECT to retrieve just about anything that's in the database (except what's in the fact tables), into a variable. (I do this when I have a FirstPlanMonth of my forecast categories, and I only want certain logic to apply for plan months in the future, not months that have passed.) *SELECT also gives you access to pretty much the full SQL string manipulation capabilities, but again it's not working against data, just master data in member tables and the like. (Otherwise, string manipulation is limited. This is an OLAP cube with numbers, not a transactional system, so the logic focuses on numbers.)
Another option is to *LOOKUP in a different time period, but the problem here is, you need to know what time period to look up in, before you look it up. Pretty hard to see how that could work.
And then you can possibly compare one time period in the data, against another time period in your *SELECT or *LOOKUP, using a series of *WHEN *IS clauses, but it wouldn't be easy.
The basic checking of whether a JUN < SEP is supported, though. This syntax works to do some basic conditional checking on the time period of the data submission, compared to FirstPlanMonth.
*XDIM_MEMBERSET TIME = PRIOR(4),%TIME_SET%,NEXT(23)
*WHEN TIME
*IS PRIOR
// do nothing for the months before the submitted time period.
*IS Category.FirstPlanMonth
// do something special for the first month -- have a sale!
// and we might need to bring in the PRIOR(4) above, if we wanted to, for example, calculate A/R based on the prior 3 months' sales.
*ELSE
// do something boring for the next 23 months
And I don't believe that you can change the member IDs of the time dimension, at least on BPC MS, to 200801. There are a number of places in the logic where it considers a PREFIX (the year) and a SUFFIX, and wants to see a period as the separator between these two. You can always try, and it's not documented anywhere that I've seen that it must be a certain way, but I learned to live with .JAN .FEB etc. -
Essbase Date Measures as DATE in OBIEE
Hi,
We have created an ASO Cube in Essbase 11.1.1 with a Date Measure member call "Maturity Date" in Measure dimension (Tagged as Accounts).
Once we create the Physical layer Administrator tool on OBIEE this member refers as a double data type. And also when we create a criteria on Answers and displays the result it is shown as a number.
But on excel (with essbase add-on) data shows as a date. (Ex: 2009-09-20)
Can anyone tell what has to be changed to display a Date Measures as Date type on OBIEE or suggest another alternate.
Thanks!
Nilaksha.Hi Nilaksha,
I thought you might say that, I think this is because Essbase doesn't use data types as such, all data is stored as a value and characteristics of that data or how it is treated are more like meta data. This certainly rings true for the time dimensions I have seen. I think your best bet is to look at how you can format the numbers in the columns to make them appear in the format you require.
Regards
Ed -
Can't seem to draw a chart (line chart) using dates rather than numbers
I'm trying to draw a Line Chart but rather using numbers i want to use dates for example: Switzerland 23/06/2008 - 23/08/2008. Can't seem to get it to work? it seems to all go wrong when I change the cell format to 'date'
Can anyone help?
Thanks
PS. I can do it easily in ExcelHello
From my point of view, it's not surprising.
In XL, a date is a number to which a date format is applied. So, it may be charted.
Same thing with the good old AppleWorks.
With Numbers, a date is NOT a number, it IS a specific class of data.
The consequence is that it can't be charted directly.
Happily, we may easily convert a date into a number.
In column B the formula is
=A-$A$1
which calculates the numeric difference between stored dates and the date stored in A1.
So, we may chart the results.
I know that it's far from perfect but we have to live with the choices made by Numbers's designers.
Yvan KOENIG (from FRANCE vendredi 18 avril 2008 18:44:14) -
How to Calculate Duration from Date Columns
Hello,
I would like to calculate duration from date columns. Using the following query
SELECT DISTINCT
EVENT_ID,
To_Char(RU.START_TIME, 'HH24:MI') START_TIME,
To_Char(RU.END_TIME, 'HH24:MI') END_TIME
FROM ROOM_USAGE RU
What I need is to subtract START_TIME from END_TIME and result should be in minutes.
Many Thanks,But, i think you need to calculate the number of days if the days are not same -
satyaki>
satyaki>
satyaki>
satyaki>with ru
2 as
3 (
4 select '05-JAN-2007 15:10:20' start_time, '07-JAN-2007 19:20:20' end_time from dual
5 union all
6 select '08-JAN-2007 05:10:20' start_time, '07-JAN-2007 07:07:20' end_time from dual
7 )
8 select ru.start_time, ru.end_time, SUBSTR(numtodsinterval(to_date(RU.END_TIME,'DD-MON-YYYY HH24:MI:SS')-to_date(RU.START_TIME,'DD-MON-YYYY HH24:MI:SS'), 'DAY'), 12, 8) duration
9 from ru;
START_TIME END_TIME DURATION
05-JAN-2007 15:10:20 07-JAN-2007 19:20:20 04:09:59
08-JAN-2007 05:10:20 07-JAN-2007 07:07:20 22:03:00
satyaki>
Or, Am i missing anything?
Regards.
Satyaki De.
is it possible to to add the duration? making the total hours to 26:12 (twentysix hours and twelve minutes)
Maybe you are looking for
-
how to set up the interaction between InDesign CS6 8.0 and Photoshop CS 6 - if Photoshop is installed and the 64 and 32-bit?? default InDesign refers to the 64-bit version of Photoshop and scripts do not work.
-
How do I edit a popupwindow/border in contribute
Hi guys..can anybody help me? so the deal is.when you on a link on my site a window pops up with text in it . I edited and added text in the window under the other text....after publishing.... the new text is there but I cant see it because the windo
-
Broken sleep/wake button.
My sleep/wake button has been broken for a while and my phone decides to turn off itself. I have plugged it up to the wall charger and the computer. But nothing has happened. I even held the home button down for a while. Is there anything I can do? O
-
Cannot use styleName and fontStyle property together in Label?
Hi All, I am using Label component with the following attributes set, see code 1) but in my CSS I defined the style myStyle as below see code 2) Here I am trying to use embed a font and use the style in the Label. I want the other styles to be given
-
Hi gurus, I have written a procedure to change the background color of the cell in EXCEL.The code is as below.. PROCEDURE set_header (p_row IN NUMBER, p_col IN NUMBER, p_value IN VARCHAR2, p_border IN VARCHAR2 DEFAULT 'N',p_bgcolor IN VARCHAR2 DE