I have one Date column in my fact table, and due to some client api requirement I need to format this column as string while grouping data using SUMMARIZE function. Below is the sample query, which I am using:
EVALUATE(
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE(
'BreakTable',
'BreakTable'[Column1],
'BreakTable'[Column2],
'BreakTable'[DateColumn1], --This needs to be formatted
),
"BreakCount",FORMAT('BreakTable'[BreakCount],"#,##0")
)
))
I have tried using FORMAT function in SUMMARIZE, and that does not work by default. I can not add new column to FactTable, so need to solve this while querying itself.
Is there any other way to achieve this? Any help is appreciated.
As per suggestion, adding more information.
We are using Sql Server 2014.
You could use the SELECTCOLUMNS() function. This function works similarly to the ADDCOLUMNS() function, except that it only returns the columns you specify.
Here is an example of how you can alter your existing query:
EVALUATE(
SELECTCOLUMNS(
SUMMARIZE(
'BreakTable',
'BreakTable'[Column1],
'BreakTable'[Column2],
'BreakTable'[DateColumn1],
),
"Column1", [Column1],
"Column2", [Column2],
"DateColumn1", FORMAT([DateColumn1],"YourFormatHere"), --Format your DateColumn here
"BreakCount",FORMAT('BreakTable'[BreakCount],"#,##0")
)
)
EDIT:
Please note that the SELECTCOLUMNS() function is only available from SQL Server 2016 and up.
Related
Can any one please tell me how to format date in MDX queries? We dont use SSRS to generate report ,we have our own customised reporting tool built on SSAS.Date filter sends date in yyyy/mm/dd format . As of now we dont have a date dimension. My date member looks like:
[CNB_DimSampleInfo].[COAReleasedON].&[2013-01-02T03:20:00].
How can I format date in STRTOmemeber? I have tried doing this. My question is how will the value coming from user suit my member format as below. I know ssrs does it easily but we are not using SSRS. Below is my Code
my code
SELECT
[Measures].[Result] ON COLUMNS
,NON EMPTY
{
[CNB_DimProduct].[ProductUcode].[ProductUcode].ALLMEMBERS*
[CNB_DimProduct].[ProductDesc].[ProductDesc].ALLMEMBERS*
[CNB_DimTest].[TestUcode].[TestUcode].ALLMEMBERS*
[CNB_DimTest].[TestName].[TestName].ALLMEMBERS*
[CNB_DimSampleInfo].[LotNo].[LotNo].ALLMEMBERS*
[CNB_DimSampleInfo].[BatchNo].[BatchNo].ALLMEMBERS*
[CNB_DimSampleInfo].[COAReleasedBy].[COAReleasedBy].ALLMEMBERS*
[CNB_DimSampleInfo].[COAReleasedON].[COAReleasedON].ALLMEMBERS*
[CNB_DimSampleInfo].[SampleReferenceNo].[SampleReferenceNo].ALLMEMBERS*
[CNB_DimSampleInfo].[AnalysedBy].[AnalysedBy].ALLMEMBERS*
[CNB_DimSampleInfo].[AnalysedOn].[AnalysedOn].ALLMEMBERS
} ON ROWS
FROM
(
SELECT
StrToMember
(
"[CNB_DimSampleInfo].[COAReleasedON].[" + Format("2013-01-02","yyyy MM")
+ "]:STRTOMember([CNB_DimSampleInfo].[COAReleasedON].["
+
Format
("2013-01-02"
,"yyyy MM"
)
+ "]"
) ON COLUMNS
FROM Cube001
);
There is also StrToSet which is better in your circumstance as you're using the : operator which returns a set:
...
...
FROM
(
SELECT
StrToSet
(
"[CNB_DimSampleInfo].[COAReleasedON].[" + Format("2013-01-02","yyyy MM")
+ "]:[CNB_DimSampleInfo].[COAReleasedON].["
+
Format
("2013-01-02"
,"yyyy MM"
)
+ "]"
,CONSTRAINED
) ON COLUMNS
FROM Cube001
);
does the following definitely return the date formatted the same as your key values?
Format("2013-01-02","yyyy MM")
Do your key values for dates look like this?...
[CNB_DimSampleInfo].[COAReleasedON].[2013 01]
Your date member
[CNB_DimSampleInfo].[COAReleasedON].&[2013-01-02T03:20:00]
looks like a bad candidate for a user date parameter, as it's precise down to the minute (perhaps the second). Unless the user exactly matches the time, they'll get nothing. But perhaps you're enforcing exact matches by using a LimitToList select list in the UI.
To get this member name, you can format the input string like this:
format([Your Input Parameter],'yyyy-MM-ddThh:mm:ss')
I have tried out using filter as below
SELECT
[Measures].[Result] ON COLUMNS
,NON EMPTY
{
filter([CNB_DimSampleInfo].[COAReleasedON].members,instr([CNB_DimSampleInfo].[COAReleasedON].currentmember.member_caption,"2013-01-02")>0 or instr([CNB_DimSampleInfo].[COAReleasedON].currentmember.member_caption, "2013-04-01")>0)
*[CNB_DimProduct].[ProductUcode].[ProductUcode].ALLMEMBERS*
[CNB_DimProduct].[ProductDesc].[ProductDesc].ALLMEMBERS*
[CNB_DimTest].[TestUcode].[TestUcode].ALLMEMBERS*
[CNB_DimTest].[TestName].[TestName].ALLMEMBERS
} ON ROWS
FROM Cube002
This view is what I am working on. It works fine,
but I intend to add the COALESCE statement in the commented
out portion to this Script. Would anyone know how to write the
Script properly. When I combined them, there was an error.
CREATE VIEW [dbo].[VW_Bzo_D]
AS WITH today AS
(SELECT *
FROM [dbo].[Bz_DAYS]
WHERE [DATE] = CAST(GETDATE() AS DATE)
),
pd AS (SELECT [DATE] AS REPORTING_PERIOD
FROM dbo.Bz_DAYS
WHERE DAY([DATE]) = 1
)
SELECT sp.*,
rp.REPORTING_PERIOD,
ac.DATE_ORDINAL AS CUSTOMER_ACCEPTANCE_ORDINAL,
mv.DATE_ORDINAL AS CUSTOMER_MOVE_ORDINAL,
today.DATE_ORDINAL TODAY_ORDINAL
/*sp.[CUSTOMER_MOVE], sp.[CUSTOMER_REQUESTED], sp.[LEASE_SIGNED_BY_GSA],
sp.[SUBMITTED_TO_GSA], sp.[CUSTOMER_ACCEPTANCE],
COALESCE(sp.[CUSTOMER_MOVE], sp.[CUSTOMER_REQUESTED], sp.[LEASE_SIGNED_BY_GSA],
sp.[SUBMITTED_TO_GSA], sp.[CUSTOMER_ACCEPTANCE]
) AS REPORT_MONTH
*/
FROM dbo.Bzo_Den sp
The error is :
Column names in each view or function must be unique. Column name
'CUSTOMER_MOVE' in view or function 'VW_Bzo_D' is specified more than
once.
I dont know if this will help but did you try aliasing the column names which is giving you trouble?
One of the other users had a similar problem and he tried aliasing. Please look at the link below
Create view in sql server "names in each view or function must be unique"
Hope it helps.
I'm new to Ruby on Rails. I'm trying to determine the proper ruby query for the following SQL query.
Select max(bid_amount) from biddings where listing_id = 1;
I need to extract the maximum value in the bid_amount column. But it has to have a dynamic listing_id.
Try:
Bidding.where('listing_id = :listing_id', listing_id: 1).maximum(:bid_amount)
Update:
To follow up on your comment: since you say you are passing in params[:id], it's best to convert that parameter to integer so that unwanted values don't go to the database. For e.g.
Bidding.where('listing_id = :listing_id', listing_id: params[:id].to_i).maximum(:bid_amount)
We are facing issue while displying the amount in ssrs reports which makes use of mdx query.
For Example : this value is retured by mdx query 278.25 but when it is binded with ssrs it shows 27.825,00.
We are using culture de-DE(German) in report.
We have tried the following solutions but still the issue remains in SSRS report:
From mdx side We have tried FORMAT_STRING = "#0,00" function for displying numeric value.
From report side we have tried to use replace function to replace '.' with ',', but its not working fine.
Sample Query can be found below
WITH
MEMBER [Measures].[CumEGTKDAmount] AS sum({[Time].[Month].FIRSTCHILD: [Time].[Month].CurrentMember},[Measures].[EGTKD] * [Measures].[AvgStockPrice])
SELECT
{
[Measures].[CumEGTKDAmount]
} ON COLUMNS,
NON EMPTY {
topcount(
(
STRTOSET("[Dim Item].[ItemHierarchy].[Item No].&[00001133]")
)
,50,[Measures].[ReklaQuote])
} ON ROWS
FROM [QM]
Thanks
Try this:
=Replace(Format(Fields!YourFieldName.Value, "#,###0.00"),",",".")
SQL query in Ms-Access
INSERT INTO tblTmpEventLog( TrackingNumber, PartNumber, PartNumberChgLvl,
EnteredBy, EventTypeSelected, EventDate )
SELECT DISTINCT tblRevRelLog_Detail.RevRelTrackingNumber,
tblRevRelLog_Detail.PartNumber, tblRevRelLog_Detail.ChangeLevel,
[Forms]![frmEventLog_Input]![EnteredBy] AS EnteredBy,
[Forms]![frmEventLog_Input]![EventTypeSelected] AS EventTypeSelected,
CDate([Forms]![frmEventLog_Input]![EventDate]) AS EventDate
FROM tblRevRelLog_Detail LEFT JOIN tblEventLog
ON (tblEventLog.PartNumber = tblRevRelLog_Detail.PartNumber)
AND (tblEventLog.PartNumberChgLvl = tblRevRelLog_Detail.ChangeLevel)
WHERE ((([tblRevRelLog_Detail]![RevRelTrackingNumber]) =
[Forms]![frmEventLog_Input]![TrackingNumber]))
AND ((tblEventLog.PartNumber) NOT IN
(SELECT tblEventLog.PartNumber FROM tblEventLog
WHERE tblEventLog.EventTypeSelected = 'pn REMOVED From Wrapper'
AND tblEventLog.TrackingNumber =
tblRevRelLog_Detail.RevRelTrackingNumber
AND tblEventLog.PartNumber = tblRevRelLog_Detail.PartNumber
AND tblEventLog.PartNumberChgLvl =
tblRevRelLog_Detail.ChangeLevel
));
DISTINCT keyword for EnteredBy, EventTypeSelected is not working..I mean, data for these columns is not displaying when I use DISTINCT keyword.
EVENTDATE is working fine, but I do not understand why is it not displaying for EneteredBy and EventTypeSelected columns.
Can anyone tell me how to handle this?
It may be that the query can't interpret properly from the form directly as the final data type. However in your date field, you are wrapping it in a function CDATE( ... ). So, the SQL engine knows the result type. I would suggest doing the same for the other fields. Ex: doing a CAST ( ...your form control... as DateTime ) as OtherColumn, etc... I THINK Access allows casting, but not positive. Otherwise, pre-pull the form value into a declared data type variable and use THAT variable in the query AS OtherColumn as you are doing.
Additionally to what #Jack mentioned, you can always go back to your account, look at your historical question, and click on whatever answers actually helped / solve your problems. Some questions never do get answers and that's ok, just give credit to those that DO help.
I have found in the past (I don't remember which old version of Access this was) that if you set the value of a form control in VBA, and then use that control in a query, the query will not see the value you set in VBA. If the user edits the control normally, the query sees the expected value. Perhaps that's what happened here.
To work around that, you can declare a VBA function that returns the desired value. For example, instead of this:
SELECT ..., Forms!MainForm!TextEntry AS TextEntry, ... FROM ...
use this:
SELECT ..., GetTextEntry() AS TextEntry, ... FROM ...
along with this:
Public Function TextEntry() As Variant
TextEntry = Forms!MainForm!TextEntry
End Function