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

Combinación de fechas de 2 columnas basadas en un ID único

Tengo una tabla que muestra la cantidad de fruta registrada para un ID específico. En la misma tabla, tengo una fecha prevista en la que podemos suponer que la cantidad de fruta es 0. Me gustaría crear una nueva tabla que inserte la fecha del "pronóstico vacío" como una cantidad de 0, con la fecha de registro.

Esta tabla se utilizará para crear un gráfico de líneas que muestre los datos registrados anteriormente y la fecha prevista más recientemente.

PBI example 2.JPG

1 ACCEPTED SOLUTION

@flyingmada - Lo siento, entendí mal el requisito. Se adjunta PBIX actualizado.

Table (17) = 
    VAR __BaseTable = ALL('Table (16)')
    VAR __Table = SELECTCOLUMNS('Table (16)',"Date",[Date Recorded],"Amount",[Amount],"Fruit",[Fruit],"Field",[Field])
    VAR __Table1a = 
            ADDCOLUMNS(
                GROUPBY(
                    'Table (16)',[Fruit],[Field],
                    "Date",MAXX(CURRENTGROUP(),[Date Recorded])
                ),
                "Forecast Empty",MAXX(FILTER(ALL('Table (16)'),'Table (16)'[Date Recorded]=EARLIER([Date]) && 'Table (16)'[Field]=EARLIER([Field]) && 'Table (16)'[Fruit]=EARLIER([Fruit])),[Forecast Empty]),
                "Amount",0
                )
    VAR __Table1 = 
        SELECTCOLUMNS(
            __Table1a,
                "Date",[Forecast Empty],
                "Amount",[Amount],
                "Fruit",[Fruit],
                "Field",[Field]
            )
RETURN
    UNION(__Table,__Table1)

@ 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

5 REPLIES 5
amitchandak
Super User
Super User

@flyingmada , Pruebe una nueva mesa como

unión (selectcolumns(Table,"Date", Table[Date recorded],"Amount", Table[Amount],"Fruit",Table[Fruit],"Field",Table[Field]),
selectcolumns(Table,"Date", Table[Date recorded],"Amount",0,"Fruit",Table[Fruit],"Field",Table[Field])
)

recomienda

https://www.sqlbi.com/articles/from-sql-to-dax-joining-tables/

@amitchandak - esto también está muy cerca, pero muestra todas las fechas previstas en la tabla. Según mi respuesta a Greg, sólo quiero incluir la fecha de "previsión vacía" basada en la fecha más reciente "fecha registrada".

Greg_Deckler
Super User
Super User

@flyingmada: puede hacerlo así en DAX, probablemente también haya una solución de Power Query. Se adjunta PBIX, Tabla (16) y Tabla (17)

Table (17) = 
    VAR __Table = SELECTCOLUMNS('Table (16)',"Date",[Date Recorded],"Amount",[Amount],"Fruit",[Fruit],"Field",[Field])
    VAR __Table1 = SELECTCOLUMNS(ADDCOLUMNS(GROUPBY('Table (16)',[Fruit],[Field],"Date",MAXX(CURRENTGROUP(),[Forecast Empty])),"Amount",0),"Date",[Date],"Amount",[Amount],"Fruit",[Fruit],"Field",[Field])
RETURN
    UNION(__Table,__Table1)

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

@Greg_Deckler - Esto está muy cerca, pero su devolución de la "última" o "más grande" de las fechas previstas, en lugar de la fecha más reciente (desde la fecha registrada) fecha prevista. Por ejemplo, tabla a continuación:

PBI example 3.JPG

@flyingmada - Lo siento, entendí mal el requisito. Se adjunta PBIX actualizado.

Table (17) = 
    VAR __BaseTable = ALL('Table (16)')
    VAR __Table = SELECTCOLUMNS('Table (16)',"Date",[Date Recorded],"Amount",[Amount],"Fruit",[Fruit],"Field",[Field])
    VAR __Table1a = 
            ADDCOLUMNS(
                GROUPBY(
                    'Table (16)',[Fruit],[Field],
                    "Date",MAXX(CURRENTGROUP(),[Date Recorded])
                ),
                "Forecast Empty",MAXX(FILTER(ALL('Table (16)'),'Table (16)'[Date Recorded]=EARLIER([Date]) && 'Table (16)'[Field]=EARLIER([Field]) && 'Table (16)'[Fruit]=EARLIER([Fruit])),[Forecast Empty]),
                "Amount",0
                )
    VAR __Table1 = 
        SELECTCOLUMNS(
            __Table1a,
                "Date",[Forecast Empty],
                "Amount",[Amount],
                "Fruit",[Fruit],
                "Field",[Field]
            )
RETURN
    UNION(__Table,__Table1)

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

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.