How to convert formula from SSRS to Power BI - reporting-services

Now I am in the task of passing some reports that are in SQL Server Reporting Services to Power BI, among them I find a report which apparently obtains the average of a value as follows:
=Format(AVG(Fields!t_TOTAL_SALIDA_seg.Value)/3600, "##") + ":" + Format(AVG(Fields!t_TOTAL_SALIDA_seg.Value) MOD 60, "##")
I have tried to pass this same formula to Power BI as follows:
= AVERAGE(Consulta1[t_TOTAL_SALIDA_seg])/3600 + AVERAGE(Consulta1[t_TOTAL_SALIDA_seg])
But its values ​​do not correspond to the report found in SSRS, I do not know if it is necessary to add something else to my formula or change something, I hope someone can give me guidance.
UPDATE:
I have made use of the formula that they tell me in one of the answers as follows:
= FORMAT( AVERAGE(Consulta1[t_TOTAL_SALIDA_seg])/3600 , "##" ) + ":" + FORMAT( AVERAGE(Consulta1[t_TOTAL_SALIDA_seg]), "##" )
But I got an error message after saving the formula
UPDATE 2:
I am comparing the results in the SSRS and Power BI report but their results do not match, the following are the values ​​in SSRS:
And these are the results in Power BI after correcting the formula:
Their results are close but they do not match anyway.
I would like to think why I still need to add MOD 60 to my Power BI formula as the report in SSRS brings it

I think that you try to convert a range of second in the average but converted in format hours/seconds.
For example, if you have 3 records :
You will get 13:32 if you respect the format ## for the Number and the mod60.
So if you want to reproduce the same in PowerBI you need to cast something like that :
= FORMAT( AVERAGE(Consulta1[t_TOTAL_SALIDA_seg])/3600 , "##" ) & ":" & FORMAT( MOD(AVERAGE(Consulta1[t_TOTAL_SALIDA_seg]),60), "##" )

Related

How to correctly translate an expression from SSRS to Power BI

I am in the task of migrating a report from SSRS to Power BI, now I find the following expression or formula in SSRS:
=Sum(
IIf(Fields!DateSend.Value < Today(),
iif(Fields!TypeRecord.Value=1, Fields!Tons.Value, Nothing)
,nothing)
)
I have tried transcribing it to a new column in Power BI as follows:
New Column = SUM(IF(Query1[DateSend] < TODAY(),
IF(Query[TypeRecord]= 1, Query1[Tons],0),0))
But I get at the end a syntax error that tells me the following:
The SUM function only accepts a column reference as an argument.
Can someone give me some guidance on how to enter the formula correctly in Power BI.

Converting mdx parameter to ssrs between dates

I have several section of similar MDX code that has been created in Microsoft SQl Server Management Studio using cube data and I now need to use the code in a SSRS paginated report. I'm getting the following error:
"Query (4, 2) The restrictions imposed by the CONSTRAINED flag in the
STRTOMEMBER function were violated."
This code works fine in Management Studio and SSRS using a date but as soon as I change the date to a parameter I get the error.
MEMBER [Measures].[Sales in Period2] AS
AGGREGATE (
{STRTOMEMBER("[Paid Date].[Date].&[2020-11-01]", CONSTRAINED) : STRTOMEMBER("
[Paid Date].[Date].&[2020-11-30]", CONSTRAINED) }
, [Measures].[Paid Amount]
),FORMAT_STRING = "#.00;(#.00);0;0"
I've tried changing:
[2020-11-01] to [#StartDate1],
[2020-11-01] to [" + #ParameterName + "],
STRTOMEMBER to STRTOSET, and
remove CONSTRAINED.
One possibly way to approach this:
This error says that your #ParameterName is not in the correct format. In your example you have the date as 2020-11-30, i.e., yyyy-MM-dd format. So, your parameter should also have the same format. If the format is same you can use it &[#ParameterName] in your StrToMember.
To achieve this, you can change the Dataset of your parameter to format it in the required format.
Since you are using MDX to get the data, you can look at the option of getting the parameter values directly from your main data set or the date dimension, Paid Date in your example.
In my sample below using the AdventureWorks sample, you can see the date format is different. You may want to show the date format in a different format to the users, but internally you would want it in the same format as your Cube wants it.
I would suggest you look at this link as well to see an example end to end flow with MDX parameters:
https://blog.pragmaticworks.com/writing-parametrized-mdx-for-reporting-services
Good luck

Implementing a date range in SSRS with the data coming from a cube

I have been trying to implement a date range parameter in SSRS 2015. The data is from a cube. I dragged my date into the dimension box of the query designer and went into the parameter tab to change the fromDate and toDate to date/time format and this resulted in the following MDX query.
SELECT ( STRTOMEMBER(#FromDate, CONSTRAINED) :
STRTOMEMBER(#ToDate, CONSTRAINED) )
My date format is dd/mm/yyyy. I have looked on several forums and tried a few method but continued to get the error:
The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function
were violated
Thank you in advance
Your parameters will need to be formed in full address mdx. e.g. #FromDate could be this - I've used the DateKey:
'[Date Dim].[Date Hier].&[20180301]'
So some concatenation, within ssrs, would be required before getting passed:
"[Date Dim].[Date Hier].&[" + 20180301 + "]" //<<you'll need to change to the names used in your cube
I'd also be tempted to use strToSet as you want a set. So mine might be something like:
( STRTOSET( "[Date Dim].[Date Hier].&[" + #FromDate + "]:" +
"[Date Dim].[Date Hier].&[" + #ToDate + "]" , CONSTRAINED) )
Here is a good reference: Range parameter on the MDX-query
The error message you received means that the parameter values do not exist in the cube in that format. To solve this you need to create a field that can be formatted and displayed to users without changing the value that the query uses.
When you create parameters in the Query Designer, it automatically creates hidden datasets which populate the Available Values for the parameter. To see this, right-click on the Datasets folder and select Show Hidden Datasets.
Now, go to the dataset properties and add a calculated field in the Fields tab. This will be your nicely formatted date.
In the parameter properties for each parameter, go to the Available Values tab. Leave the Value field the way it is, but change the Label field to the new column you created.
Now the dropdown will show the friendly label, but use the real value behind the scenes!

SSRS dataset filter

Hi I'm trying to build a report in ssrs which gives the output based on current weekending date where end day is saturday. I'm pulling my data from SSAS Cube and I have a weekending date field so I applied a filter in the query designer to get the current weekending date using a parameter I used this expression:
DateAdd("d",7-DatePart(DateInterval.Weekday,Today,FirstDayOfWeek.Sunday),Today)
When I'm executing my query, it throws an error saying the restriction imposed by the constrained flag in the STRTOSET function were violated.
Please let me know how can I fix this.
The error is thrown because you are passing a string that doesn't correspond with a valid member in your cube.
Note the Query Designer builds a MDX query based on the dimensions and members you select, this query uses the STRTOSET() function to convert your string parameter in a valid member.
...
STRTOSET(#CurrentWeekendDate,CONSTRAINED)
...
If you pass the current weekend date to your parameter it produces:
STRTOSET('2016-01-10',CONSTRAINED)
As 2016-01-10 is not a valid member in your Date dimension it throws the error.
You have to pass something like this depending on your cube:
[Date].[Date Key].&[2005-01-01T00:00:00]
So in SSRS you have to set your parameter to Text and use this expression:
CORRECT EXPRESSION:
="[200 Date].[Week Ending Date].&[" &
Format(
DateAdd("d",7-DatePart(DateInterval.Weekday,Today,FirstDayOfWeek.Sunday),Today),
"yyyy-MM-ddThh:mm:ss"
)
& "]"
UPDATE: If [Week Ending date] level doesn't include time:
="[Date].[Date Key].&[" &
Format(
DateAdd("d",7-DatePart(DateInterval.Weekday,Today,FirstDayOfWeek.Sunday),Today),
"yyyy-MM-dd"
)
& "]"
Go through this tutorial if you get stuck.
Let me know if this helps.

Cached Shared Dataset: ExecutionTime?

SQL Server Reporting Services (SSRS) 2008 R2
I've set up a shared dataset that takes a few minutes to execute. It is shared between three reports, and is the core data for these reports. (Some other datasets exist in the reports for parameter population.)
I've enabled caching on the dataset, and would like to add the dataset execution time to the reports' footers. I suppose I could add a column to the dataset with current time in SQL, but is there any SSRS function that will give this to me?
I couldn't find a pure SSRS method to get this, so as mentioned in my original post, I added a field/column to the shared dataset query. It now begins with:
SELECT
GETDATE() AS DataSetExecutionTime,
...
...
Then in the footer of the report I have a
=First(Fields!DataSetExecutionTime.Value, "DataSetName")
Thanks for the help Daytona...
jf
You can add something like this to the footer:
="Render Duration: " +
IIf(System.DateTime.Now.Subtract(Globals!ExecutionTime).TotalSeconds < 1, "0 seconds",
(
IIf(System.DateTime.Now.Subtract(Globals!ExecutionTime).Minutes > 0, System.DateTime.Now.Subtract(Globals!ExecutionTime).Minutes & " minute(s), ", "") +
IIf(System.DateTime.Now.Subtract(Globals!ExecutionTime).Seconds > 0, System.DateTime.Now.Subtract(Globals!ExecutionTime).Seconds & " second(s)", ""))
)
So a basic render time, I know thats not exactly what your looking for but the only way I know of getting the data retrieval time is from the report execution table in your report server database.