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
s45kougo
Helper I
Helper I

Calcular la mediana de los datos agregados

Hola

Esperando que alguien pueda ayudar, ya que no puedo encontrar ninguna información sobre esto...

Quiero calcular el precio medio de algunos datos agregados previamente - No tengo acceso a los datos de nivel de línea.

Una tabla simplificada tiene este aspecto:

Gasto totalCantidadPrecio
2555
20210
40104

Esto debería dar una mediana de 4. Pero, ¿cómo escribo ese cálculo?

Gracias de antemano

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@s45kougo - Aquí hay una solución mucho más elegante, Página 32, Tabla (32) de PBIX adjunto a continuación sig.

Measure 32 = 
    VAR __Table =
        GENERATE(
        'Table (32)',
        VAR __Quantity = [Quantity]
        RETURN GENERATESERIES(1,__Quantity,1)
    )
RETURN
    MEDIANX(__Table,[Price])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

@s45kougo - Aquí hay una solución mucho más elegante, Página 32, Tabla (32) de PBIX adjunto a continuación sig.

Measure 32 = 
    VAR __Table =
        GENERATE(
        'Table (32)',
        VAR __Quantity = [Quantity]
        RETURN GENERATESERIES(1,__Quantity,1)
    )
RETURN
    MEDIANX(__Table,[Price])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Oh wow, you are amazing , thank you *so* much!  This works perfectly.  I thought it must be possible, but I had no idea how to disaggregate a table.  Hope this helps someone else too in the future 🙂

Greg_Deckler
Super User
Super User

@s45kougo - Puede haber una solución más elegante y voy a pensar en ello, pero para esto se podría fuerza bruta:

Measure = 
  VAR __Table25 = 
    ADDCOLUMNS(
      GENERATESERIES(1,MAXX(FILTER('Table',[Total Spend]=25),[Quantity]),1),
      "Price",MAXX(FILTER('Table',[Total Spend]=25),[Price])
    )
  VAR __Table20 = 
    ADDCOLUMNS(
      GENERATESERIES(1,MAXX(FILTER('Table',[Total Spend]=20),[Quantity]),1),
      "Price",MAXX(FILTER('Table',[Total Spend]=20),[Price])
    )
  VAR __Table40 = 
    ADDCOLUMNS(
      GENERATESERIES(1,MAXX(FILTER('Table',[Total Spend]=40),[Quantity]),1),
      "Price",MAXX(FILTER('Table',[Total Spend]=40),[Price])
    )
  VAR __Table = UNION(__Table25,__Table20,__Table40)
RETURN
  MEDIANX(__Table,[Price])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@s45kougo , en caso de que estos datos ya estén agregados. Puede promediar

Promedio: División(Suma(Tabla[Gasto total]),sum(Tabla[Cantidad]))

Que serán cinco

Puede probar MEDIAN( Table[Price] )

Pero dudo que puedas conseguir 4

@amitchandak thanks for trying, but I do want the actual median of 4...  I'm guessing that somehow I have to calculate a table that dis-aggregates, but not sure how to do this.

Hola @s45kougo ,

Usted puede tratar de encontrar el percentil 50

Utilice la función

https://dax.guide/percentile-exc/

saludos
Harsh Nathani
¿He respondido a tu pregunta? ¡Marca mi puesto como una solución! Apreciar con un Kudos!! (Haga clic en el botón Pulgares arriba)

Thanks for your reply - unfortunately that also needs the data to be line-level.

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.