I have a task to convert existing MDX measures (from multidimensional model) into DAX (tabular model).
There is a part of code which I'm doing right now:
IIF(
[Product].[Status].Level IS [Product].[Status].[(All)]
AND
[Product].[Brand].Level IS [Product].[Brand].[(All)]
AND
[Product].[Category].Level IS [Product].[Category].[(All)]
,[Measures].[Full_Amount]
,NULL
)
How can I do the same on DAX?
The problem is to check that .[(All)] member is selected. Do we have the same option n DAX?
As #RADO mentions you can do something like this in DAX:
IF(
NOT ISFILTERED( Product[Status] )
&& NOT ISFILTERED( Product[Brand] )
&& NOT ISFILTERED( Product[Category] ),
[Measures].[Full_Amount],
BLANK()
)
Related
Okay so I have a table like shown...
I want to use PowerBI to create a new column called 'First_Interaction' where it will say 'True' if this was the user's earliest entry for that day. Any entry that came in after the first entry will be set to "False".
This is what I want the column to be like...
Use the following DAX formula to create a column:
First_Interaction =
VAR __userName = 'Table'[UserName]
VAR __minDate = CALCULATE( MIN( 'Table'[Datetime] ), FILTER( 'Table', 'Table'[UserName] = __userName ) )
Return IF( 'Table'[Datetime] = __minDate, "TRUE", "FALSE" )
Power BI dosnt support less than second so your DateTime Column must be a Text value. Take that on consideration for future transformation.
I want to filter the months of [ComptaEcriture Date] by selecting only the months from [ComptaPlanId].[ComptaDateDebut] to [ComptaPlanId].[ComptaDateFin], but since
[ComptaDateDebut] and [ComptaDateFin] are not from the same level and bot are not from the same dimension as [ComptaEcriture Date].[ComptaEcriture Date].[Month], I don't know how to achieve that.
If I could generate a range of months that would be great. My dimensions are as follows:
Assuming you're testing that PlanId is no the All member, you can use isAll MDX+ function for this.
For the set, we will combine the Filter function with a Declared function, even though we could put it all the code in the filter. It looks as :
WITH
FUNCTION inRange(Value _date,Value _start, Value _end) AS _start <= _date AND _date <= _end
SET myDates as Filter( [Date].[Date].[Month] as t, inRange(t.current.key, DateTime(2015,6,1), DateTime(2017,1,1) ) )
SELECT
myDates on 0
FROM [Cube]
And using the compact and faster version :
SELECT
Filter( [Date].[Date].[Month] as t, DateTime(2015,6,1) <= t.current.key AND t.current.key <= DateTime(2017,1,1) ) on 0
FROM [Cube]
Using the members :
WITH
FUNCTION inRange(Value _date,Value _start, Value _end) AS _start <= _date AND _date <= _end
SET myDates as Filter( [Date].[Date].[Month] as t,
inRange(t.current.key, [ComptaDateDebut].currentmember.key, [ComptaDateFin].currentmember.key )
)
SELECT
myDates on 0
FROM [Cube]
You can use contextMember instead of currentMember that check also in the slicer (FILTER BY or subselect)
We wrote this MDX query:
COUNT(
TOPPERCENT(
{[d_gca].[h_gca].[l_gca].MEMBERS},
80,
[Measures].[m_invoice_item_amount]
)
)
The problem is, when there is no value for [d_gac].[h_gac].[l_gac].MEMBERS, the displayed result is always 1.
Is there something I missed?
Can you just wrap the inner set in the NonEmpty function?
COUNT(
TOPPERCENT(
NONEMPTY(
{[d_gca].[h_gca].[l_gca].MEMBERS}
,[Measures].[m_invoice_item_amount]
),
80,
[Measures].[m_invoice_item_amount]
)
)
I am using MS SQL 2008 R2. One of my table have more than 10 lac rows — 1 lac is 105 or 100,000, so 10 lac is 1,000,000).
I want to bind this to ASP Gridview. I tried custom paging with page size and index. But grid not binded. Timeout Error occured.
Tried directly execute stored procedure, but it takes a long time.
How can I optimize this procedure ?
My procedure
ALTER PROCEDURE SP_LOAN_APPROVAL_GET_LIST
#USERCODE NVARCHAR(50) ,
#FROMDATE DATETIME = NULL ,
#TODATE DATETIME = NULL ,
#PAGESIZE INT ,
#PAGENO INT ,
#TOTALROW BIGINT OUTPUT
AS
BEGIN
SELECT *
FROM ( SELECT DOC_NO ,
DOC_DATE_GRE ,
EMP_CODE ,
EMP_NAME_ENG as Name ,
LOAN_AMOUNT ,
DESC_ENG as Discription ,
REMARKS ,
ROW_NUMBER() OVER(
ORDER BY ( SELECT 1 )
) AS [ROWNO]
from VW_PER_LOAN
Where isnull( POST_FLAG , 'N' ) = 'N'
and ISNULl( CANCEL_FLAG , 'N' ) != 'Y'
and DOC_DATE_GRE between ISNULL(#FROMDATE , DOC_DATE_GRE )
and ISNULL(#TODATE , DOC_DATE_GRE )
and BRANCH in ( SELECT *
FROM DBO.FN_SSP_GetAllowedBranches(#USERCODE)
)
) T
WHERE T.ROWNO BETWEEN ((#PAGENO-1)*#PAGESIZE)+1 AND #PAGESIZE*(#PAGENO)
SELECT #TOTALROW=COUNT(*)
from VW_PER_LOAN
Where isnull(POST_FLAG,'N')= 'N'
and ISNULl(CANCEL_FLAG,'N')!='Y'
and DOC_DATE_GRE between ISNULL(#FROMDATE,DOC_DATE_GRE)and ISNULL(#TODATE,DOC_DATE_GRE)
and BRANCH in ( SELECT *
FROM DBO.FN_SSP_GetAllowedBranches(#USERCODE)
)
END
Thanks
The first thing to do is to look at your execution plan and discuss it with a DBA if you don't understand it.
The obvious thing that stands out is that your where clause has pretty much every column reference wrapped in some sort of function. That makes them expressions and make the SQL optimizer unable to use any covering indices that might exist.
It looks like you are calling a table-valued function as an uncorrelated subquery. That would worry me with respect to performance. I'd probably move that out of the query. Instead run it just once and populate a temporary table.
I want to write a mdx script that displays the count rows I have for a member.
This is my initial script:
SELECT NON EMPTY { [Measures].[I_OPC_ATTEINT]
and 6 measures } ON COLUMNS
, NON EMPTY { ([Axe_Temps].[MOIS_ANNEE].[MOIS_ANNEE].ALLMEMBERS
* [Axe_ORGANISATION].[Structure].[EQUIPE].ALLMEMBERS
* [Axe_OPC].[TYPE_REGROUPEMENT].[TYPE_REGROUPEMENT].ALLMEMBERS
* [Axe_OPC].[COMPOSITION].[COMPOSITION].ALLMEMBERS
* [Axe_OPC].[OPC].[OPC].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( STRTOMEMBER('[Axe_ORGANISATION].[CODE_EQUIPE].&[E_1001]') ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER('[Axe_ORGANISATION].[CODE_PLATEAU].&[D_1000]') ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER('[Axe_ORGANISATION].[CODE_UNITE].&[U_107864]') ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER('[Axe_ORGANISATION].[CODE_CANAL].&[AVSC]') ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER('[Axe_Temps].[MOIS_ANNEE].&[201306]') ) ON COLUMNS
FROM [PVC_Reporting])))))
I want to display 2 calculated measures:
The count of rows of my result ( count distinct ( [Axe_OPC].[COMPOSITION].[COMPOSITION].ALLMEMBERS )
The count of rows where [Measures].[I_OPC_ATTEINT] <> 0
Thank you.
I would create a measure of type 'distinct count' within the cube and create a simple dimension (oui|non) for I_OPC_ATTEINT.