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

Populate calendar table fields between dates

This is my example pbix file.


I have got Calendar table (first one below, only first 3 rows as example) created in DAX.

Calendar = 
ADDCOLUMNS(
    CALENDARAUTO(),
    "Year", YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "mmmm" ),
    "Month Number", MONTH( [Date] )
)


JacobMotu_2-1688957026501.png

 

and Maturity table (second one). They are related by Date/SampleDate (1-*).

JacobMotu_1-1688956985310.png

 

I use a measure AAA to populate dates when there were some test results with associated Code. To this point it's ok.

 

AAA = IF(SELECTEDVALUE('Calendar'[Date]) = SELECTEDVALUE('Maturity'[SampleDate]), SELECTEDVALUE('Maturity'[Code]),"")

 

 

Goal

I have a table below, values are AAA measure as above. How to fill the days when there were no results in a way that it uses the Code from the previous test, until a new test is done? The ideal results shown in the picture below in red.

JacobMotu_0-1688956881274.png


Attempts

  1. I can't use MAX to select the last date with a Code because it would populate only the very last one everywhere (eg. B to 15/4 - 18/4 for the second row = section B) after 19/4 with a new Code result.
  2. I try to fill the gaps between the test dates with the last Code for each unique combination of Grower, Orchard, and ManagementArea (formula below). Unfortunately, the table is with no values in this case. I can't figure out where I'm making mistakes.

 

AAA = 
VAR SelectedDate = SELECTEDVALUE('Calendar'[Date])
VAR SampleCode =
    CALCULATE(
        SELECTEDVALUE('Maturity'[Code]),
        ALLEXCEPT('Maturity', 'Maturity'[SampleDate], 'Maturity'[Grower], 'Maturity'[Orchard], 'Maturity'[ManagementArea]),
        'Maturity'[SampleDate] <= SelectedDate,
        'Maturity'[Code] <> BLANK()
    )
VAR PreviousSample =
    CALCULATE(
        SELECTEDVALUE('Maturity'[SampleDate]),
        ALLEXCEPT('Maturity', 'Maturity'[Grower], 'Maturity'[Orchard], 'Maturity'[ManagementArea]),
        'Maturity'[SampleDate] < SelectedDate,
        'Maturity'[Code] <> BLANK()
    )
VAR NextSample =
    CALCULATE(
        SELECTEDVALUE('Maturity'[SampleDate]),
        ALLEXCEPT('Maturity', 'Maturity'[Grower], 'Maturity'[Orchard], 'Maturity'[ManagementArea]),
        'Maturity'[SampleDate] > SelectedDate,
        'Maturity'[Code] <> BLANK()
    )
RETURN
    IF(
        SampleCode <> BLANK(),
        SampleCode,
        IF(
            SelectedDate > PreviousSample && SelectedDate < NextSample,
            CALCULATE(
                SELECTEDVALUE('Maturity'[Code]),
                ALLEXCEPT('Maturity', 'Maturity'[SampleDate], 'Maturity'[Grower], 'Maturity'[Orchard], 'Maturity'[ManagementArea]),
                'Maturity'[SampleDate] = PreviousSample,
                'Maturity'[Code] <> BLANK()
            ),
            BLANK()
        )
    )

 

 

1 REPLY 1
lbendlin
Super User
Super User

To report on things that are not there you need to use disconnected tables and/or crossjoins

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.