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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Jakob_PBI
Frequent Visitor

Calculated table dax (complex task)

Hi

I have 2 tables

1. Forecast table 

2. Calendar table

 

The forecast is recorded on a month level and the lowest granularity is the combination of Country;Product;Type;Doses per month. And i want to change this granularity to date level.

So i basically want to sum the value for the month of demand qty and then divide it by number of days in the given month.

With help from ChatGPT i managed to create a working DAX that gives me the granularity per date, but not per date+ "Country;Product;Type;Doses".

Anyone know how i can do this?

i need this so i can combine the key with a item table.

 

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

Data model view:

Jakob_PBI_1-1682591357494.png

 

 

1 REPLY 1
johnt75
Super User
Super User

Try

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.