SSAS Rowset Action: Replace blank value from DMVs with a text string using MDX - action

Working in SSAS (inside Visual Studio Shell), I have a rowset action created that returns basic measure information from $SYSTEM.MDSCHEMA_MEASURES. Not all measures in the SSAS database have descriptions.
How can I replace BLANK description values with a simple text string "No description available."
"select [MEASURE_CAPTION], [MEASUREGROUP_NAME], [MEASURE_DISPLAY_FOLDER],[DESCRIPTION], [EXPRESSION]
from $SYSTEM.MDSCHEMA_MEASURES where [MEASURE_UNIQUE_NAME] = '" + Measures].CurrentMember.UniqueName + "'AND [CUBE_NAME] = '" + [Measures].CurrentMember.Properties("CUBE_NAME") + "'"
Returns:
Current Measure Description
Distinct Person Count
DESIRED Return:
Current Measure Description
Distinct Person Count No Description Available
Rowset Action Configuration

Is that just straight sql replacement of null or is your script returning a string "BLANK" ?
Try replacing [DESCRIPTION] with:
ISNULL([DESCRIPTION],'No Description Available')
or
CASE WHEN [DESCRIPTION] = 'BLANK' THEN 'No Description Available' ELSE [DESCRIPTION] END

Related

How to setup a stored procedure with incremental dates in Power BI

I am new to Power BI. I am using an SQL stored procedure to get the data.
execute ED_DS_TRANS_DETAIL01 #DateFrom ='2022-09-20', #DateTo = '2022-09-20'
It does give me the required data but I want it to be incremental. For example, today is the 20th and tomorrow is the 21st. So I want to set up the power bi in such a way that it gets the 21st data and then the next data 22nd and so on. Also, it doesn't replace the previous date data and places the next data underneath the previous one.
I have tried the given solution
let
Source = (Query as text) => let
Source = Sql.Database("IP", "DB" , [Query=Query, CreateNavigationProperties=false])
in
Source
in
Source
let
tdy = Date.From(DateTime.LocalNow()),
yest = Date.AddDays(tdy , - 1),
sQuery = Table.FromRecords({
[sQuery = "execute ED_DS_TRANS_DETAIL01 #DateFrom ='" & Date.ToText(yest,[Format="yyyy-MM-dd"]) & "', #DateTo = '" & Date.ToText(tdy,[Format="yyyy-MM-dd"]) & "'"
]}),
#"Invoked Custom Function" = Table.AddColumn(sQuery, "Query2", each #"Fnc Query"([sQuery]))
in
#"Invoked Custom Function"
GUI
When I click "OK" button I am getting Details: "Microsoft SQL: Incorrect syntax near '='."
You can do it at the Power Query side...
First create the parameters of dBaseIP and dBase in case you may need to change it later...
Then create a custom function which will run the SQL query "New Query" → Other Sources → "Blank Query".
let
Source = (Query as text) => let
Source = Sql.Database(dBaseIP, dBase , [Query=Query, CreateNavigationProperties=false])
in
Source
in
Source
At last, create the below function which will update your query as per today's date...
let
tdy = Date.From(DateTime.LocalNow()),
yest = Date.AddDays(tdy , - 1),
sQuery = Table.FromRecords({
[sQuery = "execute ED_DS_TRANS_DETAIL01 #DateFrom ='" & Date.ToText(yest,[Format="yyyy-MM-dd"]) & "', #DateTo = '" & Date.ToText(tdy,[Format="yyyy-MM-dd"]) & "'"
]}),
#"Invoked Custom Function" = Table.AddColumn(sQuery, "Query2", each #"Fnc Query"([sQuery]))
in
#"Invoked Custom Function"
Check this sample file... Change the database IP and name and then try to run it...

Google Sheet Formula for finding an element across multiple tabs

I`m trying to populate values in column F, "Product Sold Date" in "TABLES" tab
Basically... the logic is as follows:
1) If Column C (Product Status) = "Paused", then return "Paused"
2) If Product start date = NULL or Product end date = NULL, then return NULL
3) If Product start date < today`s date, then return "No Data"
4) If Product start date >= today`s date, return "Upcoming"
5) If product End date <= today`s date, return "Ended"
6) If product start date <= today`s date, return "In Market"
7) If the condition does not belong to any of the above cases, then return the actual Product launch dates
Below is the link to the sample data I`m working on..
I`m pasting the link itself, becaues there are multiple tabs included
https://docs.google.com/spreadsheets/d/120rHOt8Pa_PdMKPgLkSYOKTO2Cv1hBH6PpTrg7FfJLk/edit?usp=sharing
Ultimately, I need to populate the actual "Product Launch Date" by scanning data in each tab
I tried using nested if statements with combination of Index Match.
But I`m totally lost in case of multiple tabs
Can anyone please provide suggestion on this?
Should we think about using query statements instead in this case?
Sidenote: The returned values will be mix of dates and character
[In market/ Ended/ Upcoming/ No Data/ NULL/ Paused/ Actual Date]
=ARRAYFORMULA(
IF(C2:C="Paused", C2:C,
IF((A2:A="")+(B2:B=""), ,
IF(A2:A >= TODAY(), "Upcoming",
IF(B2:B <= TODAY(), "Ended",
IF(A2:A = TODAY(), "In Market",
IF(E2:E<>"", IFERROR(VLOOKUP(D2:D&E2:E,
{'Eaton Centre'!A2:A &"Eaton Centre", 'Eaton Centre'!B2:B;
'Yorkdale Mall'!A2:A&"Yorkdale Mall", 'Yorkdale Mall'!B2:B;
'Vaughan Mills'!A2:A&"Vaughan Mills", 'Vaughan Mills'!B2:B}, 2, 0)), )))))))
Your formula would be
=IF(C2="Paused",C2,if(OR(A2="",B2=""),"",IF(A2<TODAY(),"No Data",IF(A2>=TODAY(),"Upcoming",IF(B2<=TODAY(),"Ended",IF(A2<=TODAY(),"In Market","Actual Product Launch dates"))))))
In the above formula, you should be using a Query formula in place of "Actual Product Launch dates", to extract the actual date.
But the points 3 & 6 don't make any sense. The 6th condtion should be If product start date = todays date, return "In Market"

Can kettle export BLOB data from a oracle table?

I have a oracle table where I have columns like Document (type BLOB), Extension ( VARCHAR2(10) with values like .pdf, .doc) and Document Description(VARCHAR2
(100)). I want to export this data and provide to my customer.
Can this be done in kettle ?
Thanks
I have a MSSQL database that stores images in a BLOB column, and found a way to export these to disk using a dynamic SQL step.
First, select only the columns necessary to build a file name and SQL statement (id, username, record date, etc.). Then, I use a Modified Javascript Value step to create both the output filename (minus the file extension):
outputPath = '/var/output/';
var filename = outputPath + username + '_' + record_date;
// --> '/var/output/joe_20181121'
and the dynamic SQL statement:
var blob_query = "SELECT blob_column FROM dbo.table WHERE id = '" + id + "'";
Then, after using a select to reduce the field count to just the filename and blob_query, I use a Dynamic SQL row step (with "Outer Join" selected) to retrieve the blob from the database.
The last step is to output to a file using Text file output step. It allows you to supply a file name from a field and give it a file extension to append. On the Content tab, all boxes are unchecked, the Format is "no new-line term" and the Compression is "None". The only field exported is the "blob_column" returned from the dynamic SQL step, and the type should be "binary".
Obviously, this is MUCH slower than other table/SQL operations due to the dynamic SQL step making individual database connections for each row... but it works.
Good luck!

database(ETL) testing using sql server

for ETL TESTING:
when transforming from source table to destination or war house,
if a column EMPLOYEENAME is null, replace it with "" and truncate to 50 characters in sql server 2014
i got a query to replace null with "". but i have to truncate the data length if data is null.
SELECT
[EmployeeID],
ISNULL( [Employeename],'""') AS [Employeename]
FROM [dbo].[Employees]
As per my understanding of the question asked..
you need to select records and display " " (Blank) in case of Null and trim it to 50 characters for all records extending above it.
SELECT
[EmployeeID],
left(ISNULL( [Employeename],'""'),50) AS [Employeename]
FROM [dbo].[Employees]

trying to insert the data to the specific column and the row in query

I have a 2nd query where the column names are appearing and I want to insert the data in the main query. I have managed to bring all the columns of 2nd query to the main query, but the data is empty for all newly added columns.
Now I am trying to loop over the first query and trying to find the uuid which exists to insert the specific data at the specific column it finds and at the specific row based upon the uuid search. This is my try as of now:
<cfset lstusers = '51840915-e570-430d-9911-7247d076f6e7,5200915-g675-430d-9911-7247d076f6e7,56674915-e570-430d-9911-7247d076f6e7,2134563-e570-430d-9911-7247d076f6e7'>
<cfloop query="quserList">
<cfdump var="#quserList.uuid[currentRow]#">
<cfif ListContainsNoCase(lstusers,quserList.uuid[currentRow])>
<cfset QuerySetCell(quserList,"BUFFEREDRANGENOTES","name",quserList[uuid][currentRow])>
<cfset QuerySetCell(quserList,"BufferNotes","name2",quserList[uuid][currentRow])>
</cfif>
</cfloop>
</cfif>
However, it is giving me an error on the quserList[uuid][currentRow] line that says not indexable by the data:
coldfusion.sql.QueryColumn#276249a2] ] is not indexable by
51840915-e570-430d-9911-7247d076f6e7
If I try it in other way:
quserList.uuid[currentRow]
I still get an error, but it says "cannot convert to int ...". How do I fix it?
Update:
In image 1, I am doing a create column for all the above 1st query product_types into the main query and based upon the userid of 1st query and uuid of second query. I want to insert data in correct location and correct row for the user based upon uuid and userid match. Image 2 is the uuid in the second table:
In both the queries, the userid you see in the first section is common. Meaning that the same usedid exists below that tells us that this user has completed these trainings. Now I want the first query to get merged in second one so it should add correct data to the correct row and that is what messing me up.
SQL:
Query #1:
SELECT ct.trainingid,
ct.userid,
ct.trainingtype,
ct.trainingstatus,
ct.trainingscore,
ct.trainingdate,
dbo.Fn_stripcharacters(ctt.product_type, '^a-z0-9') AS product_type,
ctt.product_type AS oldName
FROM clienttraining AS ct
INNER JOIN clienttraningtypes AS ctt ON ct.trainingtype = ctt.typeid
WHERE 1 = 1
AND userid IN (
'51840915-e570-430d-9911-7247d076f6e7'
, '51927ada-6370-4433-‌​8a06-30d2d076f6e7'
)
AND trainingtype IN (
SELECT typeid
FROM complaincetestlinks
WHERE pid = 1039
AND isactive = 1
AND isdeleted = 0
)
Query 2:
SELECT id,
NAME,
username,
email,
password,
first_name,
last_name,
usertyp‌​e,
block,
sendemail,
registerdate,
lastvisitdate,
activation,
params‌​,
uuid
FROM users
WHERE uuid IN (
'51840915-e570-430d-9911-7247d076f6e7'
, '51912193-6694-4ca5-‌​94c9-9f31d076f6e7'
, '51927ada-6370-4433-8a06-30d2d076f6e7'
, '51c05ad7-d1d0-4eb6-b‌​c6b-424bd076f6e7'
, 'd047adf1-a6af-891e-94a2d0b225dcd1b6'
, '2aba38f2-d7a7-0a7a-ef‌​f2be3440e3b763'
)
Update:
Looking at it again with fresh eyes, it still seems like maybe you are over-complicating things? A simple JOIN should return the information needed, ie All users and the completed training info (if any).
Runnable SQLFiddle
SELECT u.id
, u.first_name
, u.last_name
, ct.trainingid
, ct.userid
, ct.trainingtype
, ct.trainingstatus
, ct.trainingscore
, ct.trainingdate
, ctt.product_type
, ctt.product_type AS oldName
FROM users u
LEFT JOIN clientTraining AS ct ON ct.UserID = u.UUID
LEFT JOIN clientTraningTypes AS ctt ON ct.trainingtype = ctt.typeid
LEFT JOIN (
SELECT typeID
FROM complainceTestLinks
WHERE parent_client_id = 1039
AND isactive = 1
AND isdeleted = 0
) ctl ON ctl.TypeID = ct.trainingType
WHERE u.uuid IN
(
'51840915-e570-430d-9911-7247d076f6e7'
, '51912193-6694-4ca5-94c9-9f31d076f6e7'
, '51927ada-6370-4433-8a06-30d2d076f6e7'
, '51c05ad7-d1d0-4eb6-bc6b-424bd076f6e7'
, 'd047adf1-a6af-891e-94a2d0b225dcd1b6'
, '2aba38f2-d7a7-0a7a-eff2be3440e3b763'
)
ORDER BY last_name, first_name, product_type
;
How you want to present the information, on the front end, is different question. For example, you could use a <cfoutput group="..."> to only display each user's name once, and a list of completed training courses beneath it (see below). If you need more specific advice, please post an example of the desired output.
Smith, John
Course 1
Course 2
Allen, Mark
Course 2
Course 3
...
coldfusion.sql.QueryColumn#276249a2] ] is not indexable by
51840915-e570-430d-9911-7247d076f6e7
That just means you are referencing a column name that does not exist. By omitting the quotes around uuid here quserList[uuid][currentRow], you are actually passing in the variable value as the column name, NOT the literal string "UUID". Obviously the query does not contain a column named "51840915-e570-430d-9911-7247d076f6e7". Hence the error.
it says cannot convert to int
That is pretty self explanatory. You are trying to populate a numeric column with a non-numeric value. Clearly the UUID string, ie "51840915-e570-430d-9911-7247d076f6e7" is not an integer. Either you are using the wrong value or need to change the column type.
It may be related to the fact that your QuerySetCell call is passing in the wrong parameters. The third and fourth parameter should be the "value" and query "row number". However, your code is passing in a hard coded string for "value" and the UUID string instead of a row number
QuerySetCell(quserList,"BUFFEREDRANGENOTES","name",quserList[uuid][currentRow])
That said, technically you do not even need that function. Just use associative array notation to "set" the values, ie <cfset queryName["columnName"][currentRow] = "some value here">
<cfif ListContainsNoCase(lstusers,quserList.uuid[currentRow])>
Nothing to do with the error, but ListContainsNoCase is the wrong function here, as it searches for partial matches. To match whole elements only, use ListFindNoCase.