Can't select and element from drop down - drop-down-menu

{
typeOnElement( manualItemSearchElements.mpiDestination, destination );
waitExplicitlyForVisibilityOfElement( By.xpath( manualItemSearchElements.mpiDestinationCardListLocator ), 20 );
baseTestCucumber.getCommonUtil().writeActual( "manualItemDestination", manualItemSearchElements.mpiDestinationCardList.get( 0 ).getText() );
clickOnElement( manualItemSearchElements.mpiDestinationCardList.get( 0 ) );
baseTestCucumber.getCommonUtil().writeActual( "manualItemDestination", manualItemSearchElements.mpiDestination.getAttribute( "value" ) );
baseTestCucumber.takeScreenShot();
}
here it doesn't give select the value from destination drop down
I have try to comment the
waitExplicitlyForVisibilityOfElement( By.xpath( manualItemSearchElements.mpiDestinationCardListLocator ), 20 );

Related

DaxStudio - Implementing data lineage with table variables

I have 2 problems :
When running the code below with DaxStudio, I get an error along the lines of "TREATAS function expects a complete column reference" ;
How can I implement data lineage with table variables not coming from a table of a data model?
Is there a simple way of adding to tbl_ITEMS_REFS the consolidated sum of tbl_SALES[AMOUNT]?
The code :
EVALUATE
VAR tbl_SALES =
DATATABLE(
"SALES_NBR" , INTEGER
, "ITEM_CODE" , STRING
, "AMOUNT" , INTEGER
, {
{ 1 , "X" , 10 }
, { 2 , "Y" , 10 }
, { 3 , "Z" , 10 }
, { 4 , "X" , 20 }
, { 5 , "Z" , 20 }
, { 6 , "Z" , 10 }
, { 7 , "Z" , 20 }
, { 8 , "X" , 30 }
, { 9 , "X" , 30 }
, { 10 , "Y" , 30 }
}
)
VAR tbl_ITEMS_REFS =
DATATABLE(
"Origin" , STRING
, "Code" , STRING
, {
{" Department 1 " , "X"}
, {" Department 1 " , "Y"}
, {" Department 2 " , "Z"}
}
)
VAR tbl_ITEMS_DATA_LINEAGE =
TREATAS (
SELECTCOLUMNS ( tbl_ITEMS_REFS , [Code] )
, SELECTCOLUMNS ( tbl_SALES , [ITEM_CODE] )
)
RETURN
ADDCOLUMNS (
tbl_ITEMS_DATA_LINEAGE
, "Total_Sales"
, CALCULATE (
SUM ( [AMOUNT] )
)
)
Thank you for your help.
Addendum
For question 2, by "adding to tbl_ITEMS_REFS", I was thinking of a simple way to get something like this :
Department 1 X 90
Department 1 Y 40
Department 2 Z 60
TREATAS won't work with virtual tables. If you add tbl_SALES to an actual data model so it is a real physical table and connect DAX Studio to it, the code works fine as long as you change the following:
EVALUATE
VAR tbl_ITEMS_REFS =
DATATABLE(
"Origin" , STRING
, "Code" , STRING
, {
{" Department 1 " , "X"}
, {" Department 1 " , "Y"}
, {" Department 2 " , "Z"}
}
)
VAR tbl_ITEMS_DATA_LINEAGE =
TREATAS (
SELECTCOLUMNS ( tbl_ITEMS_REFS , [Code] )
, tbl_SALES[ITEM_CODE]
)
RETURN
ADDCOLUMNS (
tbl_ITEMS_DATA_LINEAGE
, "Total_Sales"
, CALCULATE (
SUM ( tbl_SALES[AMOUNT] )
)
)

Problem in using filter context in CALCULATE

In PowerPivot DataModel I have written following DAX Code:
=VAR var1 =
CALCULATE (
SUMX ( 'CapitalPrepayment', 'CapitalPrepayment'[Amount] ),
'CapitalPrepayment'[Subject] = "Proforma",
ALL ( 'CapitalPrepayment'[EffectiveYear] )
)
VAR var2 =
CALCULATE (
SUMX ( 'CapitalPrepayment', 'CapitalPrepayment'[Amount] ),
'CapitalPrepayment'[EffectiveYear] = "1399",
'CapitalPrepayment'[Subject] = "Invoice"
)
VAR var3 =
CALCULATE (
SUMX ( 'CapitalPrepayment', 'CapitalPrepayment'[Amount] ),
'CapitalPrepayment'[Subject] = "Proforma",
'CapitalPrepayment'[EffectiveYear] = "1398"
)
VAR var5 =
CALCULATE (
SUMX ( 'CapitalPrepayment', 'CapitalPrepayment'[Amount] ),
ALL ( 'CapitalPrepayment'[Subject] )
)
RETURN
IF ( Var5 < 0, 0, IF ( Var5 = 0, 0, IF ( VAR1 + VAR2 <= 0, Var3, 0 ) ) )
and the result is:
As you can see, the problem is that grand total of [Var5] for some vendors and grand total for [Final] for all vendors is highly related to filters come from EffectiveYear ( at least Ithink so ), so the result would be zero. in addition, changing the filter context from visual ( for example removing [vendor] and [EffectiveYear] ) will disrupt the result. how can I fix this?
In my written DAX, [Var1]~[Var3] do include [subject] and [EffectiveYear] as filter arguments, but [Var5] does not for [EffectiveYear] . so I expect that the problem arise from [EffectiveYear].
I tried to include [EfectiveYear] in someway in CALCULATE but it didn't work.

How to perform a column calculation in a CALCULATE()

My table looks like this:
Doc Code
A 61
A 61X
B 62
B 61
C 61
C 62
C 62X
I am trying to create a column in DAX that just checks whether a Code contains an X by Doc. So the result should look like this:
Doc Code DAXColumn
A 61 TRUE
A 61X TRUE
B 62 FALSE
B 61 FALSE
C 61 TRUE
C 62 TRUE
C 62X TRUE
I want to do this:
DAXColumn =
VAR currentDoc = Doc
RETURN
CALCULATE(IF(ISERROR(SEARCH("X",Doc)) = TRUE, FALSE, TRUE),
FILTER(myTable,Doc = currentDoc))
It looks like I can't pass a column into the CALCULATE parameter. How could I get the results I am looking for? Thanks in advance.
Column =
VAR _1 =
SUMMARIZE (
FILTER ( _fact, CONTAINSSTRING ( _fact[Code], "X" ) ),
[Doc],
[Code]
)
VAR _2 =
CALCULATE ( MAXX ( FILTER ( _1, [Doc] = MAX ( _fact[Doc] ) ), [Code] ) )
VAR _3 =
SWITCH ( TRUE (), ISBLANK ( _2 ) = TRUE (), FALSE (), TRUE () )
RETURN
_3
Here is my suggestion - I find this code a bit more readable so it's easier to understand at a glance what is going on.
Contains X :=
VAR _codes =
CALCULATETABLE (
VALUES ( 'Table'[Code] ),
ALLEXCEPT ( 'Table' , 'Table'[Doc] )
)
VAR _filter =
FILTER (
_codes ,
CONTAINSSTRING ( [Code] , "X" )
)
VAR _count = COUNTROWS ( _filter )
RETURN IF ( _count > 0 , TRUE , FALSE )
The logic:
Calculate a single column table with all values of Code for the current (row context) value of Doc
Apply a filter over the codes table looking for the desired string
Count the rows in the remaining table
If the count is zero, the _count variable will evaluate to blank. For a non-zero count we want to return TRUE.

How to get Closing Inventory Qty right - DAX

I can't find the right results for Closing Inventory, given the scenario below:
Measure added to Matrix Table:
Calculation=
VAR minDate =
CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
VAR curDate =
SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
SWITCH (
SELECTEDVALUE ( HelperTable[ID] ),
1, IF ( curDate = minDate, [OpenInventoryMeasure], BLANK () ),
2, IF ( curDate > minDate, [ProdMeasure], BLANK () ),
3, [QtySalesMeasure],
4, if (curDate > minDate,[Closing Inventory], BLANK())
)
Here are the measures created and used in the main calculation above:
OpenInventoryMeasure =
VAR minDate =
CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
VAR curDate =
SELECTEDVALUE ( 'Calendar'[Date] )
return
CALCULATE(Sum('Production'[Qty]),FILTER('Calendar','Calendar'[Date] = minDate))
ProdMeasure =
VAR minDate =
CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
VAR curDate =
SELECTEDVALUE ( 'Calendar'[Date] )
return
CALCULATE(Sum('Production'[Value]),FILTER('Calendar','Calendar'[Date] > minDate))
QtySalesMeasure = SUM(PedItens[QTDUND])
ClosingMeasure = [OpenInventoryMeasure ] + [ProdMeasure] - [QtySalesMeasure]
Main issue: Right now, Closing measure is not giving me the right result, although the measure that make it up are correct.
Tiny issue: Also, the order is not right in the table, although I had ordered it by ID.
Here's a screenshot of the resulting table:
I appreciate any help.
The problem is with the Opening Inventory measure, because when you do the CALCULATE you are now on the context of the Monday, so it's already filtered by Monday and then you're adding an additional filter of date = 7th which returns blank.
You need to clear the filters first and then apply the date filter:
OpenInventoryMeasure =
VAR minDate =
CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
return
CALCULATE(Sum('Production'[Qty]), ALLSELECTED('Calendar'), 'Calendar'[Date] = minDate)
Your Prod measure probably suffers from the same error, but I don't understand what's the logic behind it because you only filter based on min date and not on current date.

DAX Default to last value with data

Presently my data returns:
What I need it to do is if the current month has 0's, it will default to the last months value with data:
I know this can be done with nested IF statements, but is there a better way?
UPDATED WITH #TPD SUGGESTION
The results from #TPD suggestion yield:
With measure defined as:
IF([Land Dev Alloc] = 0, CALCULATE([Land Dev Alloc],TOPN(1, CALCULATETABLE(Hyperion,FILTER(ALL(Hyperion), [Land Dev Alloc]>0)),Hyperion[DimDateID],DESC)),[Land Dev Alloc])
Where Hyperion is the main fact table that measure Land Dev Alloc pulls from
I'm not sure if this is the best way but I've recently solved a similar problem like this, assuming you have a Date table and a Value table joined with a relationship:
CurrentOrLastValue:=
CALCULATE (
-- EXTRACT VALUE FROM ROW
FIRSTNONBLANK( 'value'[value], 1 ),
-- FIRST ROW FROM YOUR 'VALUES' TABLE REDUCED TO THOSE BEFORE THE CURRENT CELL DATE
-- ORDERED BY DATE DESC
TOPN (
1,
CALCULATETABLE (
'value',
FILTER
(
ALL( 'date'[date] ),
'date'[date] <= MAX( 'date'[date] )
)
),
'value'[date],
DESC
)
)
Data tables and Pivot Table
Measure
Relationships
UPDATE TO SHOW MEASURE RESULT NOT RAW VALUE
Add a new core measure (doubling values to show a difference):
TotalValue:=SUM('value'[value]) * 2
Add a new measure to show desired output:
CurrentOrLastValueMeasure:=CALCULATE (
[TotalValue],
TOPN(
1,
CALCULATETABLE(
'value',
FILTER(
ALL( 'date'[date] ),
'date'[date] <= MAX( 'date'[date] )
)
),
'value'[date],
DESC
)
)
New measure in pivot table:
UPDATE TO SHOW LAST NON-ZERO VALUE WHEN MEASURE RETURNS ZERO
LastNonZeroMeasure:=
IF( [TotalValue] = 0,
CALCULATE (
[TotalValue],
TOPN(
1,
CALCULATETABLE(
'value',
FILTER(
ALL( 'value' ),
[TotalValue] > 0
)
),
'value'[date],
DESC
)
),
[TotalValue]
)
TotalValue not being doubled anymore. Two data points for 4th Jan to show the measure's aggregation working.
UPDATE TO IGNORE DATES AHEAD OF CELL DATE
Try filtering the dates also...
LastNonZeroMeasure:=IF( [TotalValue] = 0,
CALCULATE (
[TotalValue],
TOPN(
1,
CALCULATETABLE(
'value',
FILTER(
ALL( 'value' ),
[TotalValue] > 0
),
FILTER(
ALL( 'date' ),
'date'[date] < max( 'date'[date] )
)
),
'value'[date],
DESC
)
),
[TotalValue]
)
Ended up being far more simple than originally thought:
MeasureOne BALANCE YTD:= VAR LastNoneblankDate = CALCULATE(max('Date'[DimDateID]),FILTER(ALL('Date'),'Date'[Fiscal_Year] = MAX('Date'[Fiscal_Year])),FILTER(ALL(FactTable),[MeasureOne] > 0)) return IF([MeasureOne]=0, CALCULATE([MeasureOne],FILTER(ALL('Date'),'Date'[DimDateID] = LastNoneblankDate)), [MeasureOne BASE])
Where MeasureOne Base:
MeasureOne BASE:= VAR LastNoneblankDate = CALCULATE(max('Date'[Date]),FILTER(ALL(FactTable),[MeasureOne] > 0)) return IF(HASONEVALUE('Date'[Date]),[MeasureOne], CALCULATE([MeasureOne],FILTER(ALL('Date'),'Date'[Date] = LastNoneblankDate)))
the main issue was setting ALL(FactTable) instead of jut FactTable and handling the cases with

Resources