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
dehmos27
Frequent Visitor

¿Cómo puedo calcular el número de fechas de tiempos en una superposición de conjunto de datos?

Tengo un conjunto de datos similar al siguiente:

EventoEmpezarFinal
Abc1/1/20201/30/2020
Def1/15/20202/14/2020
Ghi3/1/20203/30/2020
Jkl3/5/20204/4/2020
Mno3/17/20204/16/2020
Pqr4/1/20204/30/2020

Quiero averiguar el número de veces que un intervalo de fechas cae en o entre las fechas de inicio y finalización de otros eventos en el conjunto de datos.

En este escenario, me gustaría crear una tabla que muestre lo siguiente:

MesTraslapos

1

2
20
33
43

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Estoy pensando en una variación de Entradas Abiertas. https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364#M147

Pero tienes que fideos en él.


@ 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

6 REPLIES 6
v-yiruan-msft
Community Support
Community Support

Hola @dehmos27 ,

¿El campo"Mi"es el número de mes? ¿Y cuál es la lógica de cálculo del campo "Traslapos"?

Saludos

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User
edhans
Super User
Super User

Pruebe esto en Power Query. Mira las fechas y ve cuántas hay entre los otros rangos. A continuación, resta 1 de ese resultado porque siempre se superpone consigo mismo.

Devuelve esta tabla:

2020-05-05 18_46_52-Untitled - Power Query Editor.png

La función clave es la siguiente:

let 
    varStart = [Start], 
    varEnd = [Final] 
in
    Table.RowCount(
        Table.SelectRows(
            #"Changed Type", 
            each (varStart >= [Start] 
                and varStart <= [Final] )
            or (varEnd >= [Start] 
                and varEnd <= [Final] )
            )
        ) -1

El código completo está a continuación. Ponga eso en una consulta en blanco:

1) En Power Query, seleccione Nuevo origen y, a continuación, Consulta en blanco
2) En la cinta inicio, seleccione el botón "Editor avanzado"
3) Retire todo lo que ve, luego pegue el código M que le he dado en ese cuadro.
4) Pulse Hecho

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckxKVtJRMtQ31DcyMDIAM40NIOxYnWgll9Q0iLQpTN5I39AEIe+ekQkUM0ZoN0bR7pWdAxaD6zbRR9Lsm5cP0WyOkDY0Q8gHFBZBxBDScMNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Event = _t, Start = _t, Final = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Event", type text}, {"Start", type date}, {"Final", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let 
    varStart = [Start], 
    varEnd = [Final] 
in
    Table.RowCount(
        Table.SelectRows(
            #"Changed Type", 
            each (varStart >= [Start] 
                and varStart <= [Final] )
            or (varEnd >= [Start] 
                and varEnd <= [Final] )
            )
        ) -1)
in
    #"Added Custom"


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Aquí está lo mismo usando una medida. Creo que tendrías problemas de rendimiento con millones de discos con esto, o incluso decenas de miles posiblemente, pero mira cómo funciona para ti. Estoy en un apreto en cuanto a si Power Query o DAX es el mejor lugar para esto. Depende de su caso de uso. La columna [Personalizado] es lo que se generó a partir de Power Query y puede ver que los resultados son los mismos.

2020-05-05 19_51_42-Untitled - Power BI Desktop.png

Overlap Count =
VAR StartDate =
    MAX( 'Table'[Start] )
VAR EndDate =
    MAX( 'Table'[Final] )
VAR Overlaps =
    // returns table with all rows that have overlaps
    FILTER(
        ALL( 'Table' ),
        ( StartDate >= 'Table'[Start]
            && StartDate <= 'Table'[Final] )
            || ( EndDate >= 'Table'[Start]
            && EndDate <= 'Table'[Final] )
    )
VAR CountOverLaps =
    /*  Counts the records in the OverLaps table and subtracts one since there is
    always one match when the record matches itself. */
    COUNTROWS( Overlaps ) - 1
RETURN
    CountOverLaps


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Greg_Deckler
Super User
Super User

Estoy pensando en una variación de Entradas Abiertas. https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364#M147

Pero tienes que fideos en él.


@ 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...
mahoneypat
Employee
Employee

No estoy totalmente seguro de haber entendido su petición, pero creo que la columna Mi en su visual fue para Mes-Año. Si no, tal vez pueda adaptar este enfoque. Esto supone que tiene una tabla Date con una columna MonthYear y no hay ninguna relación con la tabla Events con los datos de ejemplo.

Haga una tabla con la columna Date[MonthYear] y esta medida

Superposición - var mindate á MIN('Fecha'[Fecha])
var maxdate á MAX('Fecha'[Fecha])
devolver CALCULATE(COUNTROWS(Events), Events[Final]>-mindate, Events[Start]<-maxdate)+0
Lo que produce esta tabla. Sin embargo, el de febrero es diferente al tuyo. Espero que haya sido un error tipográfico.
events.png

Si esto funciona para usted, por favor márquelo como la solución. Los felicitaciones también son apreciados. Por favor, avísame si no.

saludos

palmadita





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.