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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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!:
Mastering Power BI 2nd Edition

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!:
Mastering Power BI 2nd Edition

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!:
Mastering Power BI 2nd Edition

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors