Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
zudar
Post Patron
Post Patron

No sólo primero y último, sino también segundo.. o Nth.

Hola a todos

Tengo problemas con una tabla de matriz y me vendría bien tu ayuda.

Lo que quiero es bastante simple y todo esto viene de una sola tabla en mi modelo: tengo una dimensión en las columnas y otra en las filas. Digamos fechas en las columnas y personas de ventas en las filas. Como valores, quiero poner los ID de pedido que mi gente de ventas vendió en un solo día.

Descubrí que cuando arrastro en el ID de pedido, PowerBI me está dando la opción de elegir 'primero' o 'último' (así puedo mostrar dos ID de pedido arrastrando en 'ID de pedido' dos veces y elegir 'primero' y 'último'), pero quiero mostrar, digamos, hasta 10 ID de pedido por persona por día (más de 10 es prácticamente imposible). Otro problema al que me enfrenté es que cuando se utilizan las opciones 'primer' y 'último' es que cuando solo hay un ID de pedido, se muestra dos veces, porque es el primer y último ID de pedido para esa persona ese día.

¿Cuál es el mejor enfoque con DAX para lograr esto?

Quiero mostrar algo como esto, con LOS ID de pedido en orden ascendente por persona y día:

1-11-20202-11-2020
JohnPrimera orden49184926
Segunda Orden49194928
Tercera Orden4923
GuillermoPrimera orden49174925
Segunda Orden49204927
Tercera Orden 4929
CharlesPrimera orden49214930
Segunda Orden49224931
Tercera Orden4924
3 REPLIES 3
Anonymous
Not applicable

[Nth Order] =
var __nth = 1 // change this to any n you want
// Get OrderID's from the 1st highest
// in the context to the __nth highest.
var __orderIDs =
    TOPN(__nth,
        DISTINCT( Orders[OrderID] ),
        Orders[OrderID],
        desc
    )
// Get the order id with the lowest
// id. This could be the __nth one
// you're looking for.
var __nthOrderID =
    MINX(
        __orderIDs,
        Orders[OrderID]
    )
// If there are exactly __nth
// orders, it means you've got
// the __nth order in there
// you're after.
var __shouldDisplay =
    COUNTROWS( __orderIds ) = __nth
var __output =
    if( __shouldDisplay,
        __nthOrderID
    )
return
    __output
amitchandak
Super User
Super User

@zudar , Crear una columna de rango como

Rankx(filter(Table, [customer] ?earlier([customer]) && [date] ?earlier([date])),[ORDER ID],asc)

@amitchandak

Y luego probaby algo como:

Third Order = MAXX(
    TOPN( 1, FILTER (
        Orders,
        Orders[Rank] = 3
    )),Orders[Order ID])

etcetera.. ?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.