I have following DAX code. I need auto increment row number where FileNo and CI_No code are same. I tired with RANKX function but it return rank as 1 for all records. Any one have any idea how we can achieve this using DAX.
Thanks in advance.
Dax code:
DEFINE
VAR A = UNION( ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 301, "Amount" ,300))
VAR B= ADDCOLUMNS(A,
"RowNo", RANKX(
FILTER(A,
[FileNo]=EARLIER([FileNo]) && [CI_No]=EARLIER([CI_No])
),
[Amount], , DESC
) )
EVALUATE B
Expected Result
You can try with mix of AddIndexColumn (from TransformData) and new Calculated column:
RowNo =
RANKX(
FILTER( ALLEXCEPT('sample','sample'[RowNo]) , [FileNo] = EARLIER('sample'[FileNo]) && [CL_No] = EARLIER('sample'[CL_No]) ),
[DummySum], , DESC
)
DummySum = sum('sample'[Index])
EDIT:
Table = VAR A = ADDCOLUMNS(UNION( ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 301, "Amount" ,300)), "Index", [Amount]+RAND())
VAR B= ADDCOLUMNS(A,
"RowNo", RANKX(
FILTER(A,
[FileNo]=EARLIER([FileNo]) && [CI_No]=EARLIER([CI_No])
),
[Index], , DESC
) )
return B
Related
I have a table that contains 3 columns:
Order
Date
State
Each row / record shows if the state was changed:
Now I would like to calculate the number of order that are below state 3 for each date in the calendar.
In the example above you can see there is nor entry for order 100 for 07.01.2022. But for this date the order is still below 3 as you can see in the record before.
How would you do that?
I think this might be better to do in PowerQuery.
Suppose the table mentioned in your question is order_state:
let
Source = Table.FromRows(
{
{100, 1, "1/1/2022"},
{100, 2, "1/5/2022"},
{100, 3, "1/8/2022"},
{101, 1, "1/5/2022"},
{101, 2, "1/6/2022"},
{101, 3, "1/7/2022"},
{102, 1, "1/7/2022"},
{102, 2, "1/9/2022"},
{102, 3, "1/10/2022"}
},
{"Order", "Status", "Date"}
),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}})
in
#"Changed Type"
Then I believe you can calculate what you want with a query like this:
let
start_date = List.Min(order_state[Date]),
end_date = List.Max(order_state[Date]),
days = Duration.Days(end_date - start_date),
dates = Table.FromList(List.Dates(start_date,days,#duration(1, 0, 0, 0)), Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),
joined = Table.AddColumn(
dates,
"order_state_rows",
(current) => Table.RowCount(
Table.Distinct(
Table.SelectColumns(
Table.SelectRows(
order_state,
(row) => (row[Date] <= current[Date] and row[Status] <> 3)
)
,{"Order"}
)
)
)
)
in
joined
Which gives this result:
I have following DAX code. I need comma separated holiday list based on Week No . I tired with CONCATENATEX function and it combine all comma separated holiday list in each row instead of week wise. Any one have any idea how we can achieve below expected using DAX.
Dax Code:
DEFINE
VAR A = UNION( ROW ("WeekNo", 1, "USAHoliday", "New Year", "CANHoliday","New Year")
,ROW ("WeekNo", 16, "USAHoliday", "Easter Sunday", "CANHoliday","Easter Sunday")
,ROW ("WeekNo", 16, "USAHoliday", "", "CANHoliday","Easter Monday")
,ROW ("WeekNo", 27, "USAHoliday", "Independence Day", "CANHoliday","")
,ROW ("WeekNo", 28, "USAHoliday", "", "CANHoliday","Independence Day")
,ROW ("WeekNo", 22, "USAHoliday", "Memorial Day", "CANHoliday","")
)
VAR AHoliday = DISTINCT(FILTER( UNION(SELECTCOLUMNS(A,
"WeekNo",[WeekNo]
,"Holiday",[USAHoliday]
),
SELECTCOLUMNS(A,
"WeekNo",[WeekNo]
,"Holiday",[CANHoliday]
)
),[Holiday]<>""))
VAR HolidayList=SUMMARIZE(AHoliday
,[WeekNo]
,"HolidayList.", CONCATENATEX(AHoliday,[Holiday],",", [Holiday],ASC)
)
EVALUATE HolidayList
Expected Result
HolidayList should be defined as, for example:
SUMMARIZE(
AHoliday,
[WeekNo],
"HolidayList",
CONCATENATEX(
FILTER( AHoliday, [WeekNo] = EARLIER( [WeekNo] ) ),
[Holiday],
", "
)
)
Hi I am trying to copy only one item from a list into another list.
Example 1:
listFinalDevices = listDevices.map((index) => index).toList();
works a bit, but this overwrites the listFinalDevice every time, I need to add the selected Item from the listDevice. As a kind of favorite device list.
Example 2:
listFinalDevices.insertAll(listFinalDevices.length,listDevices.map((index) => index).toList());
This copy the complete list but I need only the over index referenced item.
Can someone give me a link to an example or what are the keywords for what I have to search.
UPDADTE:
To make it more clearer, currently I have the following data in the list named listDevices:
[ScanResult{device: BluetoothDevice{id: 4D:55:F7:CE:03:FA, name: , type: BluetoothDeviceType.unknown, isDiscoveringServices: false, _services: [], advertisementData: AdvertisementData{localName: , txPowerLevel: null, connectable: true, manufacturerData: {}, serviceData: {0000fd6f-0000-1000-8000-00805f9b34fb: [215, 226, 39, 186, 231, 145, 9, 162, 217, 184, 33, 163, 133, 92, 23, 221, 40, 117, 217, 176]}, serviceUuids: [0000fd6f-0000-1000-8000-00805f9b34fb]}, rssi: -65}, ScanResult{device: BluetoothDevice{id: 00:80:E1:21:C4:B5, name: P2PSRV1, type: BluetoothDeviceType.le, isDiscoveringServices: false, _services: [], advertisementData: AdvertisementData{localName: P2PSRV1, txPowerLevel: null, connectable: true, manufacturerData: {33537: [0, 0, 32, 0, 0, 128, 225, 33, 196, 181]}, serviceData: {}, serviceUuids: []}, rssi: -35}, ScanResult{device: BluetoothDevice{id: 60:29:4D:9B:AC:52, name: , type: BluetoothDeviceType.unknown, isDiscoveringServices: false, _services: [], advertisementData: Adver
The target is, that I chose some Devices and put this to a kind of favorite list which should named with listFinalDevices:
[ScanResult{device: BluetoothDevice{id: 00:80:E1:21:C4:B5, name: P2PSRV1, type: BluetoothDeviceType.le, isDiscoveringServices: false, _services: [], advertisementData: AdvertisementData{localName: P2PSRV1, txPowerLevel: null, connectable: true, manufacturerData: {33537: [0, 0, 32, 0, 0, 128, 225, 33, 196, 181]}, serviceData: {}, serviceUuids: []}, rssi: -35}, ScanResult{device: BluetoothDevice{id: C5:9F:97:96:4A:A9, name: MX Anywhere 2S, type: BluetoothDeviceType.le, isDiscoveringServices: false, _services: [], advertisementData: AdvertisementData{localName: MX Anywhere 2S, txPowerLevel: 4, connectable: false, manufacturerData: {}, serviceData: {}, serviceUuids: [00001812-0000-1000-8000-00805f9b34fb]}, rssi: -50}] is not empty
listFinalDevices.add(listDevices[index])
Could you be clearer? You wanted to add object at index from another list to final list, right?
or maybe:
listFinalDevices.add(listDevices[listDevices.indexWhere((el) => el == index)])
I want to make a shiny app that show a table depends the parameters enter
tabla4<- reactive({
tabla<-activos_vabs[activos_vabs$Comunidades==input$com4 & activos_vabs$Sexo==input$sexo4 & activos_vabs$Edad==input$edad4, ];
return(tabla);
})
I have this and it doesn't show anything , but if i give the values, not with the input its works
tabla4<- reactive({
tabla<-activos_vabs[activos_vabs$Comunidades=="Total Nacional" & activos_vabs$Sexo=="Ambos sexos" & activos_vabs$Edad=="Total", ];
return(tabla);
return(prueba[5])
})
I have a big table, and i just want to print a part .
The below sample shiny code will solve your requirement.
library(shiny)
ui <- fluidPage(selectInput(inputId = "selectedName", label = "Select a name",
choices = levels(data$name)),
tableOutput("table")
)
server <- function(input, output, session){
df <- reactive({data.frame(data[data$name == input$selectedName,])
})
output$table <- renderTable( df() )
}
shinyApp(ui = ui, server = server)
data used in code is below.
dput(data)
structure(list(name = structure(c(1L, 2L, 6L, 5L, 4L, 3L, 1L,
1L, 1L, 2L, 2L, 2L, 5L, 5L, 5L), .Label = c("aaa", "ddd", "eee",
"ggg", "ppp", "yyy"), class = "factor"), test = c(14, 88, 36,
25, 56, 34, 30, 75, 44, 19, 83, 49, 87, 62, 50), result = c(25,
44, 39, 88, 10, 44, 58, 22, 94, 56, 73, 15, 84, 223, 45)), .Names = c("name",
"test", "result"), row.names = c(NA, -15L), class = "data.frame")
Filtering of dataframe depends on the selection we make in selectInput dropdown.
I have a dataframe like this:
df = pd.DataFrame({'Year' : ['2010', '2010', '2010', '2010', '2010', '2011', '2011', '2011', '2011', '2011', '2012', '2012', '2012', '2012', '2012'],
'Name' : ['Bob', 'Joe', 'Bill', 'Bob', 'Joe', 'Dave', 'Bob', 'Joe', 'Bill', 'Bill', 'Joe', 'Dave', 'Dave', 'Joe', 'Steve'],
'Score' : [95, 76, 77, 85, 82, 92, 67, 80, 77, 79, 82, 92, 64, 71, 83]})
I would like to get the Z Score for each Name in each Year.
I can do it if subset the Year column like this:
(df[df.Year == '2010'].groupby(['Year', 'Name'])['Score'].mean() - df[df.Year == '2010'].groupby(['Year', 'Name'])['Score'].mean().mean()) / ( df[df.Year == '2010'].groupby(['Year', 'Name'])['Score'].mean().std())
Is there a cleaner way of doing it?
There is a zscore functionality in scipy, but be careful the default delta-degree-of-freedom is 0 in scipy.stats.zscore:
In [171]:
import scipy.stats as ss
S=(df[df.Year == '2010'].groupby(['Year', 'Name'])['Score'].mean())
pd.Series(ss.zscore(s, ddof=1), S.index)
Out[171]:
Year Name
2010 Bill -0.714286
Bob 1.142857
Joe -0.428571
dtype: float64