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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors