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
Aleksandra_MLT
Advocate I
Advocate I

Last no blank per category

Hola, community.

 

I have a fact table which brings values per category and inconsistently. Meaning some days are missing and those missing days differ per category. I want to fill those gaps with the dates for each category and give them last no blank value (corresponding to the category). I would prefer this doing in PQ. but DAX is also appreciated ( calculated column). 

 

I checked a nioce solution here but it does not seem to mind the category so was struggling to apply that. 

The current situation: 

Aleksandra_MLT_0-1686313409493.png

Desired solution: 

Aleksandra_MLT_1-1686313439122.png

 

1 ACCEPTED SOLUTION

@Aleksandra_MLT 
Please refer to updated sample file with the calculated table proposed solution

1.png

Table 2 = 
ADDCOLUMNS (
    CROSSJOIN (
        CALENDAR ( MIN ( 'Table'[Date] ), MAX ( 'Table'[Date] ) ),
        ALLNOBLANKROW (  'Table'[Category] )
    ),
    "Value", 
    MAXX ( 
        TOPN ( 
            1,
            FILTER ( 
                'Table', 
                'Table'[Category] = EARLIER ( 'Table'[Category] )
                    && 'Table'[Date] <= EARLIER ( [Date] )
            ),
            'Table'[Date]
        ),
        'Table'[Value]
    )
)

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @Aleksandra_MLT 
Please refer to attached sample file with the proposed solution

1.png2.png

Value Measure = 
VAR CurrentDate = MAX ( 'Date'[Date] )
VAR CurrentCategoryTable = CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Category] ) )
VAR TableBefore = FILTER ( CurrentCategoryTable, 'Table'[Date] < CurrentDate ) 
VAR PreviousRecord = TOPN ( 1, TableBefore, 'Table'[Date] )
VAR Result = SUMX ( PreviousRecord, 'Table'[Value] )
RETURN 
    IF ( 
        ISINSCOPE ( 'Table'[Category] ), 
        COALESCE ( SUM ( 'Table'[Value] ), Result )
    )

Thank you for quick reply, @tamerj1 !

 

But I would prefer a calculated column cause I need a row context. I mentioned it as well 🙂 

@Aleksandra_MLT 

A calculated column cannot add new rows. Perhaps you mean a new calculated table?

@tamerj1 , indeed, CC will not expand table, apologies for confusion. So yes, either calculated table either power query.

@Aleksandra_MLT 
Please refer to updated sample file with the calculated table proposed solution

1.png

Table 2 = 
ADDCOLUMNS (
    CROSSJOIN (
        CALENDAR ( MIN ( 'Table'[Date] ), MAX ( 'Table'[Date] ) ),
        ALLNOBLANKROW (  'Table'[Category] )
    ),
    "Value", 
    MAXX ( 
        TOPN ( 
            1,
            FILTER ( 
                'Table', 
                'Table'[Category] = EARLIER ( 'Table'[Category] )
                    && 'Table'[Date] <= EARLIER ( [Date] )
            ),
            'Table'[Date]
        ),
        'Table'[Value]
    )
)

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.