How to SortByColumns, Search, Filter in powerapps - search

I got it to search for one column, but how to I add more items? ie "Material", "Destination",etc
SortByColumns(
Search(
Filter(
'Transfer Request',
"Not-Completed" in Putaway.Value
),
Search_SC.Text,
"Material"
),
"ID",
If(
SortDescending1,
Ascending,
Descending
)
)

The Search function can search over multiple columns:
SortByColumns(
Search(
Filter( 'Transfer Request', "Not-Completed" in Putaway.Value ),
Search_SC.Text,
"Material", "Destination", "OtherColumn" ),
"ID",
If( SortDescending1, SortOrder.Ascending, SortOrder.Descending ) )

Related

filter a list of tuples using filter() function and lambda expression

I am learning Python programming;i'm trying to filter a list of tuples using filter() function and lambda expression. but there is something wrong.
The code I have tried is as follows:
state_and_population = [
( 'Uttar Pradesh' , 199812341 ),
( 'Maharashtra' , 112372972 ),
( 'Bihar' , 103804637 ),
( 'West Bengal' , 91347736 ),
( 'Madhya Pradesh' , 72597565 ),
( 'Tamil Nadu' , 72138958 ),
( 'Rajasthan' , 68621012 ),
( 'Karnataka' , 61130704 ),
( 'Gujarat' , 60383628 ),
( 'Andhra Pradesh' , 49386799 )
]
filtered_object = filter( lambda s_a_p: [ s_a_p[0] , s_a_p[1] < 0 ] ,state_and_population )
print( list( filtered_object ) )
The list should print an empty list according to my given condition but it is showing all the elements
[('Uttar Pradesh', 199812341), ('Maharashtra', 112372972), ('Bihar', 103804637), ('West Bengal', 91347736), ('Madhya Pradesh', 72597565), ('Tamil Nadu', 72138958), ('Rajasthan', 68621012), ('Karnataka', 61130704), ('Gujarat', 60383628), ('Andhra Pradesh', 49386799)]
Your lambda lambda s_a_p: [ s_a_p[0] , s_a_p[1] < 0 ] returns a non-empty list which, in Python, is considered a True boolean that, in turn, causes filter to accept the corresponding item from the iterator.
Write the lambda as follows: lambda e: e[1] < 0

Excel Pivot Table_Same column and row item with more than one values

I have a table like this
I hope I can get the latest value when a product has more than one value in a same measurement item by excel pivot table. Like this:
I tried so hard but still have no way to achieve this...
Any idea? Thanks.
You'll need to add your source data to the Data Model (via the Power Pivot ribbon), after which you can create the following measures:
Weight
VAR LatestDate =
MAXX( 'Table', IF( 'Table'[measure item] = "weight", 'Table'[time] ) )
RETURN
MAXX(
'Table',
IF(
'Table'[measure item] = "weight",
IF( 'Table'[time] = LatestDate, 'Table'[value] )
)
)
Height
VAR LatestDate =
MAXX( 'Table', IF( 'Table'[measure item] = "height", 'Table'[time] ) )
RETURN
MAXX(
'Table',
IF(
'Table'[measure item] = "height",
IF( 'Table'[time] = LatestDate, 'Table'[value] )
)
)
Create a Pivot Table with these two measures in the Values field together with product name in the Rows field.

DAX percentiles of sums

I have a table with the following fields:
[Date]
[Ref Nr]
[Units]
I'd like to do a SUM over [Units] for each value in [Date] and [Ref Nr] and then take a 80 percentile for each value in [Ref Nr].
I've tried the following but it doesn't work...
DEFINE
MEASURE 'Table'[Pctl] =
CALCULATE(
PERCENTILEX.INC(
'Table',
CALCULATE(
SUM('Table'[Units]),
ALLEXCEPT('Table',
'Table'[Date],
'Table'[Ref Nr]
)
),
0.8
),
ALLEXCEPT('Table',
'Table'[Ref Nr]
)
)
EVALUATE
FILTER(
SUMMARIZE(
'Table',
'Table'[Ref Nr],
"Percentile 80",
'Table'[Pctl]
),
'Table'[Pctl] <> 0
)
Could you please guide me how to make it work?
Thanks in advance :)
I think your Pct1 calculation should look as follows:
MEASURE 'Table'[Pctl] =
CALCULATE(
PERCENTILEX.INC(
VALUES('Table'[Date],
CALCULATE(SUM('Table'[Units])),
0.8
)
)
as it will be evaluated in the context of [Ref Nr] in the final query, VALUES('Table'[Date]) will only return dates for the current [Ref Nr], the rest of the calculation should be clear I think

PowerPivot Filter Function

In PowerPivot Excel 2016 I write a formula to summarize year to date sales using filter function as below:
SalesYTD:=CALCULATE (
[Net Sales],
FILTER (
ALL ( Sales),
'sales'[Year] = MAX ( 'Sales'[Year] )
&& 'Sales'[Date] <= MAX ( 'Sales'[Date] )
)
)
And it's work perfectly, now in my data I have a field called "Channel" which I want to filter it in my pivot table but it won't works!
Does anybody knows how should I fix this formula?!
Thanks in advance...
Try:
SalesYTD:=CALCULATE (
[Net Sales],
FILTER (
ALLEXCEPT ( 'Sales', 'Sales'[Channel] ),
'sales'[Year] = MAX ( 'Sales'[Year] )
&& 'Sales'[Date] <= MAX ( 'Sales'[Date] )
)
)
ALLEXCEPT removes all context filters in the table except filters that have been applied to the specified columns, in this case [Channel] column.
Let me know if this helps.

Using Case to match strings in sql server?

I am trying to use CASE in a SQL Select statement that will allow me to get results where I can utilize the length of one string to produce the resutls of another string. These are for non-matched records from two data sets that share a common ID, but variant Data Source.
Case statement is below:
Select Column1, Column2,
Case
When Column1 = 'Something" and Len(Column2) = '35' Then Column1 = "Something Else" and substring(Column2, 1, 35)
End as Column3
From dbo.xxx
When I run it I get the following error:
Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '='.
You need to have a value for each WHEN, and ought to have an ELSE:
Select Data_Source, CustomerID,
CASE
WHEN Data_Source = 'Test1' and Len(CustomerName) = 35 THEN 'First Value'
WHEN Data_Source = 'Test2' THEN substring(CustomerName, 1, 35)
ELSE 'Sorry, no match.'
END AS CustomerName
From dbo.xx
FYI: Len() doesn't return a string.
EDIT:
A SQL Server answer that addresses some of the comments might be:
declare #DataSource as Table ( Id Int Identity, CustomerName VarChar(64) )
declare #VariantDataSource as Table ( Id Int Identity, CostumerName VarChar(64) )
insert into #DataSource ( CustomerName ) values ( 'Alice B.' ), ( 'Bob C.' ), ( 'Charles D.' )
insert into #VariantDataSource ( CostumerName ) values ( 'Blush' ), ( 'Dye' ), ( 'Pancake Base' )
select *,
-- Output the CostumerName padded or trimmed to the same length as CustomerName. NULLs are not handled gracefully.
Substring( CostumerName + Replicate( '.', Len( CustomerName ) ), 1, Len( CustomerName ) ) as Clustermere,
-- Output the CostumerName padded or trimmed to the same length as CustomerName. NULLs in CustomerName are explicitly handled.
case
when CustomerName is NULL then ''
when Len( CustomerName ) > Len( CostumerName ) then Substring( CostumerName, 1, Len( CustomerName ) )
else Substring( CostumerName + Replicate( '.', Len( CustomerName ) ), 1, Len( CustomerName ) )
end as 'Crustymore'
from #DataSource as DS inner join
#VariantDataSource as VDS on VDS.Id = DS.Id
Select
Column1,
Column2,
Case
When Column1 = 'Something' and Len(Column2) = 35
Then 'Something Else' + substring(Column2, 1, 35)
End as Column3
From dbo.xxx
Update your query on
use '+' for string concat
len() returns int, no need to use ''
remove "Column1 =" in the case when condition
replace "" with ''
Hope this help.

Resources