I have a large database of stock movements. I want to be able to see if we are sending stock back to the originating plant after it has already shipped the item out.
A miniature version of my data base it below:
Date
Part No.
Origin
Destination
Cost
Quantity
1/29/2023
100
MIA
MCO
$500.00
500
1/29/2023
100
MIA
ATL
$450.00
500
1/30/2023
100
JFK
MIA
$700.00
500
1/30/2023
100
MCO
SFB
$700.00
500
the expected result would be an output table that summarizes the following:
Column A
Column B
# of plants with inbound and outbound
2
inbound and outbound quantity
1500
inbound outbound % of volume
75%
Here you go.
Create 3 measures as follows:
# of plants with inbound and outbound =
VAR o = VALUES('Table'[Origin])
VAR d = VALUES('Table'[Destination])
RETURN COUNTROWS(INTERSECT(o, d))
inbound and outbound quantity =
VAR o = VALUES('Table'[Origin])
VAR d = VALUES('Table'[Destination])
VAR i = INTERSECT(o, d)
RETURN CALCULATE(SUM( 'Table'[Quantity]), 'Table'[Origin] IN i)
inbound outbound % of volume =
[inbound and outbound quantity]/SUM('Table'[Quantity])
Related
I have two tables one with data about franchise locations (Franchise Profile Info) and one with Award data. Each franchise location is given a certain number of awards they are allowed to give out per year. Each franchise location rolls up to a larger group depending on where in the country they are located. These tables are in a 1 to 1 relationship using Franchise ID. I am trying to create a matrix with the number of awards, total utilized, and percentage utilized rolled up to group with the ability to expand the groups and see individual locations. For some reason when I add the value fields a blank row is created. There are not any blank rows in either of the original tables so I'm not sure where this is coming from.
Franchise Profile Info table
ID
Franchise Name
Group
Street Address
City
State
164
Park's
West
12 Park Dr.
Los Angeles
CA
365
A & J
East
243 Whiteoak Rd
Stafford
VA
271
Otto's
South
89 Main St.
St. Augustine
FL
Award table
ID
Year
TotalAwards
Utilized
164
2022
16
12
365
2022
5
5
271
2022
22
17
This tables are in a relationship with a 1 to 1 match on ID
What I want the matrix to look like
Group
Total Awards
Utilized
%Awards Utilized
East
5
5
100%
West
16
12
75%
South
22
17
77%
Instead what I'm getting is this
Group
Total Awards
Utilized
%Awards Utilized
East
5
5
100%
West
16
12
75%
South
22
17
77%
0
0
0%
I can't for the life of me figure out where this row is coming from. I can add in the Group and Franchise name as rows but as soon as I add any of the value columns this blank row shows up.
You have a value on the many side that does not exist on the one side. You can read a full explanation here. https://www.sqlbi.com/articles/blank-row-in-dax/
I'm having a lot of trouble figuring out how to get RANKX to behave at different levels of a hierarchy.
I have a hierarchy structure as follows:
Region
Manager
Supervisor
Agent
For simplicity sake, let's rank each level on the total number of Requests Handled. I want to rank each level of the hierarchy against everyone at that level. For example, at the Agent level, each agent's total Requests Handled should be ranked against every other agent, regardless of what supervisor, manager, or region they are in.
I can get the agent level to work just fine with the following, but I can't figure out how to get the upper levels to rank against each other. This works fine if I apply the same RANKX statement at any level, but only when one level is shown in a visual. When adding any additional levels it breaks.
Requests Handled Measure =
SUMX('Work Done',[Requests Handled])
Rank Measure =
IF(
ISINSCOPE(Roster[Associate Name]) && NOT(ISBLANK([Requests Handled Measure])),
RANKX(
ALL(Roster[Associate Name], Roster[Supervisor Name], Roster[Manager Name], Roster[Region]),
[Requests Handled Measure],,DESC,Dense
)
)
The ideal result would be something like:
- Region 1 240 Requests Rank 2
- Manager A 122 Requests Rank 2
- Supervisor A 65 Requests Rank 3
- Agent A 30 Requests Rank 9
- Agent B 35 Requests Rank 5
- Supervisor B 57 Requests Rank 4
- Agent C 29 Requests Rank 10
- Agent D 28 Requests Rank 11
- Manager B 118 Requests Rank 3
- Supervisor C 65 Requests Rank 3
- Agent E 33 Requests Rank 6
- Agent F 32 Requests Rank 7
- Supervisor D 53 Requests Rank 6
- Agent G 26 Requests Rank 13
- Agent H 27 Requests Rank 12
- Region 2 250 Requests Rank 1
- Manager C 99 Requests Rank 4
- Supervisor E 56 Requests Rank 5
- Agent I 25 Requests Rank 14
- Agent J 31 Requests Rank 8
- Supervisor F 43 Requests Rank 7
- Agent K 20 Requests Rank 16
- Agent L 23 Requests Rank 15
- Manager D 151 Requests Rank 1
- Supervisor G 78 Requests Rank 1
- Agent M 40 Requests Rank 1
- Agent N 38 Requests Rank 2
- Supervisor H 73 Requests Rank 2
- Agent O 36 Requests Rank 4
- Agent P 37 Requests Rank 3
I am trying to put together a DAX statement in Power BI to calculate the quartiles of a table according to some filters. I did a generic sentence however, I have problems to be able to assign the filters to it.
The table structure is:
Campaing
management
group
id_oper
name_oper
nom_sup
tickets
convergente
bo tecnico
convergente
0000000
operador1
supervisor1
500
convergente
bo tecnico
convergente
11111111
operador2
supervisor1
200
convergente
bo tecnico
convergente
22222222
operador3
supervisor1
80
convergente
bo tecnico
convergente
33333333
operador4
supervisor1
300
despacho
bo despacho
averias
44444444
operador5
supervisor2
1500
despacho
bo despacho
averias
55555555
operador6
supervisor2
500
despacho
bo despacho
averias
66666666
operador7
supervisor2
30
despacho
bo despacho
averias
77777777
operador8
supervisor2
1000
multiskill
bo provision
multiskill
88888888
operador9
supervisor3
20
multiskill
bo provision
multiskill
99999999
operador10
supervisor3
5
multiskill
bo provision
multiskill
12345678
operador11
supervisor3
80
multiskill
bo provision
multiskill
87654321
operador12
supervisor3
3
And the Power BI query that i'm using is this:
Quantile =
IF(TBL_CUARTIL[tickets]<= PERCENTILE.EXC(TBL_CUARTIL[tickets],0.25),"Q4",
IF(AND(TBL_CUARTIL[tickets]> PERCENTILE.EXC(TBL_CUARTIL[tickets],0.25),TBL_CUARTIL[tickets]<= PERCENTILE.EXC(TBL_CUARTIL[tickets],0.5)),"Q3",
IF(AND(TBL_CUARTIL[tickets]> PERCENTILE.EXC(TBL_CUARTIL[tickets],0.5),TBL_CUARTIL[tickets]<= PERCENTILE.EXC(TBL_CUARTIL[tickets],0.75)),"Q2",
IF(TBL_CUARTIL[tickets]> PERCENTILE.EXC(TBL_CUARTIL[tickets],0.75),"Q1"))))
The query calculates the quartile by operator and it works without problems, but it calculates them on the total of records, and I would like to know how I can calculate the same but with data filters, for example filters of the campaign column.
I would appreciate your help with this problem, and I hope I have explained ... thank you very much
Use New measure:
Quantile=
var cur_val = max(TBL_CUARTIL[tickets])
return IF(cur_val< PERCENTILEX.EXC(ALLSELECTED(TBL_CUARTIL), TBL_CUARTIL[tickets], 0.25),"Q4",
IF(AND(cur_val> PERCENTILEX.EXC(ALLSELECTED(TBL_CUARTIL), TBL_CUARTIL[tickets], 0.25),cur_val<= PERCENTILEX.EXC(ALLSELECTED(TBL_CUARTIL), TBL_CUARTIL[tickets], 0.5)),"Q3",
IF(AND(cur_val> PERCENTILEX.EXC(ALLSELECTED(TBL_CUARTIL), TBL_CUARTIL[tickets], 0.5),cur_val<= PERCENTILEX.EXC(ALLSELECTED(TBL_CUARTIL), TBL_CUARTIL[tickets], 0.75)),"Q2",
IF(cur_val> PERCENTILEX.EXC(ALLSELECTED(TBL_CUARTIL), TBL_CUARTIL[tickets], 0.75),"Q1"))))
We have a social like app, and we started using the AWS ElasticcSearch Service in production, but we started to have a problem with ES, the ES version is the 2.3.
The cluster configuration is:
Data node: 2
Data node types: m3.medium.elasticsearch
Dedicated master instance count: 3
Dedicated master instance type: t2.small.elasticsearch.
Capacity of each data node: 50GB.
The problem is that in less than thirty minutes one of the node free storage size went from 9 GB to 0 GB, we did not know how this happened.
We have 4 types of documents, where one of them is a dynamic type, lets call it Group type, that is because every document of Group can have N fields that represents the friends of a Group.
Something like
{
13: [1,2,3,4],
5: [1,3,4],
user_ids: [1,2,3,4,6,7],
id: 1
}
This means that the users with ID 13 and 5 are friends with some of the users of the Group with ID 1.
So this document can grows according to the amount of users.
If anyone had or has the same problem, or just fully understand the Elastic Search architecture it would be awesome his help.
Indices info:
curl -XGET 'http://host/_cat/indices?v
health status index pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana-4 1 1 5 0 1.9mb 1017.3kb
green open X 1 1 2259502 29575 57.5gb 28.7gb
green open Y 1 1 113156 0 21.7mb 10.8mb
curl -XGET 'http://host/_cat/nodes?v&h=host,id,ip,rp,hp,d,cpu,v,r,m,n
host id ip rp hp d cpu v r m n
x.x.x.x tIgm x.x.x.x 95 5 5.7gb 0 2.3.2 - m Shatter
x.x.x.x puUF x.x.x.x 95 6 5.7gb 0 2.3.2 - m Justice
x.x.x.x 1qZi x.x.x.x 97 54 17.7gb 7 2.3.2 d - Allatou
x.x.x.x lcty x.x.x.x 97 60 17.7gb 8 2.3.2 d - Amergin
x.x.x.x Nq1H x.x.x.x 5 15 5.7gb 0 2.3.2 - * Arkus
Thanks a lot!
I have managed to resolve the problem.
My problem is known as Mapping Explosion
Having variables keys in the mapping, like I had in the Group document type, will result on an evergrowing index.
I have one dataframe in the following form:
df = pd.read_csv('data/original.csv', sep = ',', names=["Date", "Gran", "Country", "Region", "Commodity", "Type", "Price"], header=0)
I'm trying to do a self join on the index Date, Gran, Country, Region producing rows in the form of
Date, Gran, Country, Region, CommodityX, TypeX, Price X, Commodity Y, Type Y, Prixe Y, Commodity Z, Type Z, Price Z
Every row should have all the different commodities and prices of a specific region.
Is there a simple way of doing this?
Any help is much appreciated!
Note: I simplified the example by ignoring a few attributes
Input Example:
Date Country Region Commodity Price
1 03/01/2014 India Vishakhapatnam Rice 25
2 03/01/2014 India Vishakhapatnam Tomato 30
3 03/01/2014 India Vishakhapatnam Oil 50
4 03/01/2014 India Delhi Wheat 10
5 03/01/2014 India Delhi Jowar 60
6 03/01/2014 India Delhi Bajra 10
Output Example:
Date Country Region Commodit1 Price1 Commodity2 Price2 Commodity3 Price3
1 03/01/2014 India Vishakhapatnam Rice 25 Tomato 30 Oil 50
2 03/01/2014 India Delhi Wheat 10 Jowar 60 Bajra 10
What you want to do is called a reshape (specifically, from long to wide). See this answer for more information.
Unfortunately as far as I can tell pandas doesn't have a simple way to do that. I adapted the answer in the other thread to your problem:
df['idx'] = df.groupby(['Date','Country','Region']).cumcount()
df.pivot(index= ['Date','Country','Region'], columns='idx')[['Commodity','Price']]
Does that solve your problem?