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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Syndicate_Admin
Administrator
Administrator

Tabla calculada dax (tarea compleja)

Hola

Tengo 2 mesas

1. Tabla de pronóstico

2. Tabla del calendario

El pronóstico se registra a nivel mensual y la granularidad más baja es la combinación de País; Producto; Tipo;Dosis por mes. Y quiero cambiar esta granularidad al nivel de fecha.

Así que básicamente quiero sumar el valor del mes de cantidad de demanda y luego dividirlo por el número de días en el mes dado.

Con la ayuda de ChatGPT, logré crear un DAX funcional que me da la granularidad por fecha, pero no por fecha + "País; Producto; Tipo;Dosis".

¿Alguien sabe cómo puedo hacer esto?

Necesito esto para poder combinar la clave con una tabla de elementos.

Forecast qty per date = 
VAR StartDate = MIN('_dimDate'[Date]) // Get the minimum date from the date table
VAR EndDate = MAX('_dimDate'[Date]) // Get the maximum date from the date table
RETURN
    // Iterate through each date in the date table
    ADDCOLUMNS(
        FILTER(
            '_dimDate',
            '_dimDate'[Date] >= StartDate && '_dimDate'[Date] <= EndDate
        ),
        "_dimDate", '_dimDate'[Date],
        
        // Calculate the forecast value for the current date by distributing it evenly across all days in the month
        "Forecast_Qty_per_date", 
            CALCULATE(
                SUM('Forecast'[Demand_qty]), 
                DATESBETWEEN(
                    '_dimDate'[Date],
                    DATE(YEAR('_dimDate'[Date]), MONTH('_dimDate'[Date]), 1),
                    DATE(YEAR('_dimDate'[Date]), MONTH('_dimDate'[Date]), DAY(EOMONTH('_dimDate'[Date], 0)))
                )
            ) / (DAY(EOMONTH('_dimDate'[Date], 0))) - DAY(DATE(YEAR('_dimDate'[Date]), MONTH('_dimDate'[Date]), 1)) + 1
    )

Jakob_PBI_0-1682591249554.png

Vista del modelo de datos:

Jakob_PBI_1-1682591357494.png

1 REPLY 1
Syndicate_Admin
Administrator
Administrator

Probar

Forecast qty per date =
VAR SummaryTable =
    ADDCOLUMNS (
        SUMMARIZE (
            'Forecast',
            'Forecast'[Country],
            'Forecast'[Product],
            'Forecast'[Type],
            'Forecast'[Doses per month],
            'Forecast'[DateKey]
        ),
        "@End of month", EOMONTH ( 'Forecast'[DateKey], 0 ),
        "@Days in month", DATEDIFF ( 'Forecast'[DateKey], EOMONTH ( 'Forecast'[DateKey], 0 ), DAY ) + 1,
        "@Total qty", CALCULATE ( SUM ( 'Forecast'[Demand_qty] ) )
    )
VAR DailySummary =
    ADDCOLUMNS (
        GENERATE ( SummaryTable, CALENDAR ( 'Forecast'[DateKey], [@End of month] ) ),
        "@Daily amount", DIVIDE ( [@Total qty], [@Days in month] )
    )
RETURN
    DailySummary

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors