How to convert SQL to DAX - sql

I have the following DAX statement but i have no idea how to convert it into a DAX query.
Si([Ticket State]="12. Cerrado / Closed";
NingúnFiltro(Máx([Fecha de Ajuste Final]
En ([Ticket Id];[Create Time Note])) En ([Ticket Id]);Todos);"")
I know that is in spanish, so, if = si and en = in .
Thank you in advance

Related

How to remove multiple possible prefixes from a Name string in SQL Server

I need to correct Names of users by removing prefixes before I can process the names.
For example, my list of prefixes is:
am, auf, auf dem, aus der, d, da, de, de l’, del, de la, de le, di, do, dos, du,
im, la, le, mac, mc, mhac, mhíc, mhic giolla, mic, ni, ní, níc, o, ó,
ua, ui, uí, van, van de, van den, van der, vom, von, von dem, von den, von der
I want to remove any of these prefixes from the First Name if they are present.
For example - inputs:
Outputs:
I know I can take a brute force approach and do a replace 40 odd times, but was wondering if there is a better/smarter way to do this, given the list of names that need to be processed can be in the tens of thousands, daily.
Thank you
You could use apply:
select t.*, v.prefix_free_first_name
from t outer apply
(select top (1) left(t.first_name, len(t.first_name) - len(v.prefix) - 1) as prefix_free_first_name
from (values ('am'), ('auf'), . . .
) v(prefix)
where t.first_name like '% ' + v.prefix
order by len(v.prefix) desc
) v;
Note: This handles the situation where multiple prefixes match a name, such as "de le" and "le".

How to store Spanish text in SQL server

I need to store Spanish text in SQL server.
I am using varchar data type for string fields and collation is 'SQL_Latin1_General_CP1_CI_AS'.
Will it support for Spanish text?
Yes u could store in this way :
CREATE TABLE #TM(NAME NVARCHAR(MAX));
INSERT INTO #TM
VALUES(N'El hardware inalámbrico no autorizado se puede introducir fácilmente');
Explanation :
N actually stands for National language character set Which means that you are passing an NCHAR, NVARCHAR or NTEXT value
from Microsoft https://msdn.microsoft.com/en-IN/library/ms186939.aspx
Result :
NAME
El hardware inalámbrico no autorizado se puede introducir fácilmente

Regular expression Oracle

I am learning to use regular expressions and I'm using them to limit the results of a search query by using the REGEXP_LIKE in Oracle 11. Placing an example of the data available, I have the following:
Plan navegación 200 MB
Plan navegación 1 GB
Plan navegación 1 GB
Plan de navegacion 3G
Plan de navegacion 4G
Plan de navegacion 3G Empresarial
Plan de navegacion 4G Empresarial
Plan de servicios 3G
Plan de servicios 4G
Plan navegación Datos
I want this result is limited to the following (Only 3G, 4G):
Plan de navegacion 3G
Plan de navegacion 4G
Plan de navegacion 3G Empresarial
Plan de navegacion 4G Empresarial
I am using the following search pattern but I did not properly filtered results:
Upper(PLAN_GSM),'(NAVEGA){1}|(3G|4G|5G)'
Upper(PLAN_GSM),'((NAVEGA)+)(3G|4G)+'
I have done several tests and do not find the solution. Someone could give me hints?
You could simply use LIKE, as below:
select *
from mytable
where PLAN_GSM LIKE 'Plan de navegacion _G%';
or use REGEXP_LIKE, as below:
select *
from mytable
where REGEXP_LIKE(PLAN_GSM, '^Plan de navegacion (3|4|5)G(*)');
SQL Fiddle demo
Reference:
Oracle/PLSQL: REGEXP_LIKE Condition on Tech on the Net
You can use this:
SELECT * FROM mytable
WHERE REGEXP_LIKE(mycolumn, '\APlan de navegacion \dG.*\z', 'c');
\d represents a digit
\A is the beginning of the string
.* greedily matches any characters
\z is the end of the string
select *
from all_tab_columns
where COLUMN_NAME like '%MAIN%ACCOUNT%LINK%CODE%N%' and TABLE_NAME like 'CB%' and not regexp_like(table_name,'[0-9]')
The above query will fetch the only object without number of content.
select *
from all_tab_columns
where COLUMN_NAME like '%MAIN%ACCOUNT%LINK%CODE%N%' and TABLE_NAME like 'CB%' and not regexp_like(table_name,'[0-9]')
The above query will fetch only object with numbers content.

VISUALTOTALS and UNION in MDX inconsistent

I have a problem with a MDX request:
The following query gives me the good partial results
WITH
SET [Paiments Encaisse] AS { [Type Paiement].[Type Paiement Id].&[13]
,[Type Paiement].[Type Paiement Id].&[20]
,[Type Paiement].[Type Paiement Id].&[31]
,[Type Paiement].[Type Paiement Id].&[62]}
MEMBER [Measures].[CA Encaissé]
AS
SUM(
[Paiments Encaisse],[Measures].[Montant HT Partage Encaisse]
)
MEMBER Measures.[CA Encaissé-E] AS [Measures].[CA Encaissé]
MEMBER MEASURES.[CA Encaissé-H] AS
([Measures].[CA Encaissé],[Hors En CDP].[Hors ou En CDP].&[False] )
SELECT
{Measures.[CA Encaissé-E],MEASURES.[CA Encaissé-H]} ON 0,
NON EMPTY{
{[Hors En CDP].[Hors ou En CDP].&[True]} * VISUALTOTALS([Employes].[Hie Societe].MEMBERS)*
[CDP Propriétaire].[Centre de Profits].[All]
} ON 1
FROM NON VISUAL
( SELECT {[Employes].[Societe].&[1234]} ON 0,{[CDP Propriétaire].[Societe].&[1234]} ON 1 FROM [Prévisions] )
WHERE (
[Type Fantome].[Val].&[False],
[Date Facturation du Paiement].[Year].&[2011-01-01T00:00:00],
[Date Paiement].[Year].&[2011-01-01T00:00:00],
[Date Facturation Opération].[Year].&[2011-01-01T00:00:00])
However, the follwoing query, that aims at giving me the whole results, returns me less rows on the first part of the UNION than the first query, which baffles me
WITH
SET [Paiments Encaisse] AS { [Type Paiement].[Type Paiement Id].&[13]
,[Type Paiement].[Type Paiement Id].&[20]
,[Type Paiement].[Type Paiement Id].&[31]
,[Type Paiement].[Type Paiement Id].&[62]}
MEMBER [Measures].[CA Encaissé]
AS
SUM(
[Paiments Encaisse],[Measures].[Montant HT Partage Encaisse]
)
MEMBER Measures.[CA Encaissé-E] AS [Measures].[CA Encaissé]
MEMBER MEASURES.[CA Encaissé-H] AS
([Measures].[CA Encaissé],[Hors En CDP].[Hors ou En CDP].&[False] )
SELECT
{Measures.[CA Encaissé-E],MEASURES.[CA Encaissé-H]} ON 0,
NON EMPTY{ UNION
({[Hors En CDP].[Hors ou En CDP].&[True]} * VISUALTOTALS([Employes].[Hie Societe].MEMBERS)*
[CDP Propriétaire].[Centre de Profits].[All]
, {[Hors en CDP].[Hors ou En CDP].&[False],[Hors en CDP].[Hors ou En CDP].[All]}
* {[Employes].[Hie Societe].[All]} *
VISUALTOTALS ([CDP Propriétaire].[Centre de Profits].ALLMEMBERS
),ALL
)} ON 1
FROM NON VISUAL
( SELECT {[Employes].[Societe].&[1234]} ON 0,{[CDP Propriétaire].[Societe].&[1234]} ON 1 FROM [Prévisions] )
WHERE (
[Type Fantome].[Val].&[False],
[Date Facturation du Paiement].[Year].&[2011-01-01T00:00:00],
[Date Paiement].[Year].&[2011-01-01T00:00:00],
[Date Facturation Opération].[Year].&[2011-01-01T00:00:00])
What's more, the column Measures.[CA Encaissé-H] is always NULL in the second query, even on lines where there should be a value.
What I do not understand is why the results in the first part of the union are influenced by what happens in the second part. Could someone please explain it to me ?
I'm not a specialist of SSAS; but I can share my experience with icCube; VisualTotal() is changing the way a hierarchy is actually aggregated and if you've several calls of this function into the same request this become quite weird as possibly non deterministic (depending on order of evaluation) and difficult to understand.
META : I attached a big bounty to this question, so far, the only answer is a description of the effects, not the inner working of VISUALTOTALS.

Group By in xquery

I am trying to convert the following code to xquery so that the results remain the same. I am trying to calculate the total freight costs for each customer
SELECT
c.CompanyName, SUM(o.freight) AS [Total Freight Costs]
FROM
Customers c, Orders o
WHERE
c.CustomerID = o.CustomerID
GROUP BY
CompanyName
The test data for the customers.xml and orders are as follows
<dataroot>
<Customers>
<CustomerID>ALFKI</CustomerID>
<CompanyName>Alfreds Futterkiste</CompanyName>
<ContactName>Maria Anders</ContactName>
<ContactTitle>Sales Representative</ContactTitle>
<Address>Obere Str. 57</Address>
<City>Berlin</City>
<PostalCode>12209</PostalCode>
<Country>Germany</Country>
<Phone>030-0074321</Phone>
<Fax>030-0076545</Fax>
</Customers>
<Customers>
<CustomerID>ANATR</CustomerID>
<CompanyName>Ana Trujillo Emparedados y helados</CompanyName>
<ContactName>Ana Trujillo</ContactName>
<ContactTitle>Owner</ContactTitle>
<Address>Avda. de la Constitución 2222</Address>
<City>México D.F.</City>
<PostalCode>05021</PostalCode>
<Country>Mexico</Country>
<Phone>(5) 555-4729</Phone>
<Fax>(5) 555-3745</Fax>
</Customers>
</dataroot>
Orders.xml
<dataroot>
<Orders>
<OrderID>10248</OrderID>
<CustomerID>WILMK</CustomerID>
<EmployeeID>5</EmployeeID>
<OrderDate>1996-07-04T00:00:00</OrderDate>
<RequiredDate>1996-08-01T00:00:00</RequiredDate>
<ShippedDate>1996-07-16T00:00:00</ShippedDate>
<ShipVia>3</ShipVia>
<Freight>32.38</Freight>
<ShipName>Vins et alcools Chevalier</ShipName>
<ShipAddress>59 rue de l&apos;Abbaye</ShipAddress>
<ShipCity>Reims</ShipCity>
<ShipPostalCode>51100</ShipPostalCode>
<ShipCountry>France</ShipCountry>
</Orders>
</dataroot>
This is what I have so far
for $o in doc("Orders.xml")/dataroot/Orders,
$c in doc("Customers.xml")/dataroot/Customers[CustomerID = $o/CustomerID]
return
<OrderDetails>
{
$c/CompanyName,
sum($o/Freight)
}
</OrderDetails>
Simple enough:
(: select only customers with at least one order :)
for $c in doc("Customers.xml")/dataroot/Customers
[doc("Orders.xml")/dataroot/Orders/CustomerID=./CustomerID]
(: get the list of orders for this customer :)
let $o := doc("Orders.xml")/dataroot/Orders[CustomerID = $c/CustomerID]
(: ...and properly encapsulate the calculated value in the result :)
return
<OrderDetails>
{$c/CompanyName}
<TotalFreight>{sum($o/Freight)}</TotalFreight>
</OrderDetails>
The test data you gave has no matching CustomerIDs, however, so it returns nothing for this query; I had to mock up my own. With that done, however, I get output akin to the following:
<OrderDetails>
<CompanyName>Alfreds Futterkiste</CompanyName>
<TotalFreight>45.58</TotalFreight>
</OrderDetails>
Actually, since XQuery 3.0 there is a standardized "group by" for FLWOR expressions.