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
Tings2
New Member

How to repeat the latest measure result that doesn't show blank

Hi,

I have a measure that returns a result that I want to show for each month. However, the data behind the measure is not available for all months and will therefore return a blank when no data is available in the underlying fact table.

I have been asked to repeat the latest available result for each month until new data is available. I have pasted an example of what I'm trying to achieve below:

 

Current Result

 CurrentOutput.png


Desired Result

Month YearResult
Nov-2215
Dec-2215
Jan-2310
Feb-2310
Mar-2310
Apr-2310
May-2310

 

Model Snapshot

The measure calculates a result using a field in the All Metrics table which is then aggregated up to a Control from the Controls table.

The Month Year field is from the Date table which is linked to day_date in the All Metrics table via fulldatealternatekey.

Model.png

 

Measure Snapshot

The current measure in use will return a 0 when there is no data available for a given month which is the correct behaviour in most contexts. 

However, I need a separate measure to repeat the latest result by month year.

Current Measure

Tings2_0-1685673465877.png

 

Proposed Measure

I've been attempting a number of variants on the below measure:
Tings2_1-1685673768081.png

The trouble is I can easily remove the filter context being applied to the day_date  in the visual and return a non blank result for all records in the all_metrics table but I can't reapply the filter context to make sure only the latest result is returned.

If someone could please help me work out to show only the latest non blank result that would be so helpful.

Thank you!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

HI,

I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1685677340568.png

 

Result measure: = 
VAR _currentrow =
    MAX ( 'Calendar'[Month Year sort] )
VAR _monthyeartable =
    ADDCOLUMNS (
        FILTER (
            ALLSELECTED ( 'Calendar'[Month Year], 'Calendar'[Month Year sort] ),
            'Calendar'[Month Year sort] <= _currentrow
        ),
        "@result", CALCULATE ( SUMX ( Data, Data[Price] * Data[Qty] ) )
    )
VAR _nonzeromaxmonthyear =
    MAXX ( FILTER ( _monthyeartable, [@result] <> 0 ), 'Calendar'[Month Year sort] )
RETURN
    IF (
        HASONEVALUE ( 'Calendar'[Month Year] ),
        CALCULATE (
            SUMX ( Data, Data[Price] * Data[Qty] ),
            FILTER (
                ALLSELECTED ( 'Calendar' ),
                'Calendar'[Month Year sort] = _nonzeromaxmonthyear
            )
        )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

HI,

I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1685677340568.png

 

Result measure: = 
VAR _currentrow =
    MAX ( 'Calendar'[Month Year sort] )
VAR _monthyeartable =
    ADDCOLUMNS (
        FILTER (
            ALLSELECTED ( 'Calendar'[Month Year], 'Calendar'[Month Year sort] ),
            'Calendar'[Month Year sort] <= _currentrow
        ),
        "@result", CALCULATE ( SUMX ( Data, Data[Price] * Data[Qty] ) )
    )
VAR _nonzeromaxmonthyear =
    MAXX ( FILTER ( _monthyeartable, [@result] <> 0 ), 'Calendar'[Month Year sort] )
RETURN
    IF (
        HASONEVALUE ( 'Calendar'[Month Year] ),
        CALCULATE (
            SUMX ( Data, Data[Price] * Data[Qty] ),
            FILTER (
                ALLSELECTED ( 'Calendar' ),
                'Calendar'[Month Year sort] = _nonzeromaxmonthyear
            )
        )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.

Top Solution Authors