Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Here is my problem.
I have a visual showing me the cheapiest offers for a series of Shipping Companies for some regions.
What I need is to count how many "wins" each Shipping Company had for each State, and sum the Shipping Cost only for those lines. Right now what I have is the total number of records for each company and the sum for all Shipping Cost for that particular ShipCo and I'm about to lost my mind.
Below you can find an image of the table and the pbi and xlsx files for download:
- https://freeimage.host/i/BBNtcv
- https://www.mediafire.com/file/5bdy6uaj2vsx15j/Dash_Frete.zip/file
Thanks in advance.
Solved! Go to Solution.
Hi @leonardoficz ,
Try the following formula to create measures:
Min_ShipCost =
CALCULATE(
MIN(ShipService[ShipCost]),
FILTER(
ALLSELECTED(ShipService),
ShipService[DocNo] = MAX(ShipService[DocNo])
)
)
ShipCo =
CALCULATE(
MAX(ShipService[ShippingCo]),
FILTER(
ShipService,
ShipService[ShipCost] = [Min_ShipCost]
)
)
Count_Win =
VAR tab =
FILTER(
ALLSELECTED('ShipService'),
VAR mincost = [Min_ShipCost]
VAR SegmentForCost =
FILTER (
'ShipService',
'ShipService'[DocNo] = 'ShipService'[DocNo]
&&'ShipService'[ShipCost] = mincost
)
VAR Istab = NOT ISEMPTY(SegmentForCost)
RETURN Istab
)
VAR Result =
CALCULATE (
COUNTROWS( 'ShipService' ),
KEEPFILTERS(tab)
)
RETURN
IF(
ISFILTERED(ShipService[ShippingCo]),
Result,
DISTINCTCOUNT(ShipService[DocNo])
)
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @leonardoficz ,
What do you consider a win? Do youn want to count the number of lines that correspond to thje shipcost Min value for each state?
For example for the TRP001 stata DF is 2 (8.21) and for ES is 1 for 9.38
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHey MFelix.
Let me try to explain better.
This is an excel sheet with around 35000 DocNo.s for each shipping company, they are all the same. What I mean is, there is 35k DocNo.s for TRP001, 35k for TRP002 and so on. For each DocNo. we have a shipping cost value for each shipping company. Something like that:
DocNo. ------------ ShpCompany --------- Shipping Cost
330000 ------------ TRP 001 --------------- 35.01
330000 ------------ TRP 002 --------------- 18.89
330000 ------------ TRP 003 --------------- 13.74
330000 ------------ TRP 004 --------------- 70.80
In this case, TRP003 offers the best price, which means it wins the auction for that particular DocNo. That happens for each one of the 35k DocNo.s.
What I want is to count how many wins each shipping company had.
=====================================================
Em português, já que vi que vc é brasileiro tbem --'
Meu arquivo base, que está sendo levado pro pbi é um arquivo com 35k mock nfs pra cada transportadora pra fazer uma simulação de custo de fretes com diversos cenários.
Cada uma das NFs (docno.) tem vinculado a ela um preço de frete, uma transportadora (que oferece o menor preço) e um estado.
O que eu quero é contar as notas onde cada transportadora oferece o menor preço, pra cada uma das 35k notas. Por exemplo, se a TRP001 ofereceu o menor preço em 2000 notas, eu quero que apareça esse 2000 e não o número total de notas.
Também é preciso que de acordo com essa primeira parte aí em cima, seja somado o valor dos fretes onde cada transportadora venceu o leilão, dando assim um panorama geral de qual é o gasto que eu tería se usasse aquela transportadora.
A se considerar: a transportadora pode ou não levar encomendas para um determinado CEP, caso não leve, o preço do frete será 0, mas esse valor já está excluído no filtro geral. Por isso que na tabela 2 para a TRP001 17k notas que é o total de notas que aquela transportadora leva.
Não sei se deu pra entender. Se não deu, eu posso te passar o .xlsx e o .pbi pra vc dar uma olhada.
Hi @leonardoficz ,
Try the following formula to create measures:
Min_ShipCost =
CALCULATE(
MIN(ShipService[ShipCost]),
FILTER(
ALLSELECTED(ShipService),
ShipService[DocNo] = MAX(ShipService[DocNo])
)
)
ShipCo =
CALCULATE(
MAX(ShipService[ShippingCo]),
FILTER(
ShipService,
ShipService[ShipCost] = [Min_ShipCost]
)
)
Count_Win =
VAR tab =
FILTER(
ALLSELECTED('ShipService'),
VAR mincost = [Min_ShipCost]
VAR SegmentForCost =
FILTER (
'ShipService',
'ShipService'[DocNo] = 'ShipService'[DocNo]
&&'ShipService'[ShipCost] = mincost
)
VAR Istab = NOT ISEMPTY(SegmentForCost)
RETURN Istab
)
VAR Result =
CALCULATE (
COUNTROWS( 'ShipService' ),
KEEPFILTERS(tab)
)
RETURN
IF(
ISFILTERED(ShipService[ShippingCo]),
Result,
DISTINCTCOUNT(ShipService[DocNo])
)
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
106 | |
89 | |
81 | |
76 | |
73 |
User | Count |
---|---|
112 | |
104 | |
96 | |
74 | |
66 |